

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/broswer.jpg">
  <link rel="icon" href="/img/broswer.jpg">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Feng Zikai">
  <meta name="keywords" content="">
  
    <meta name="description" content="首先我们先明白一个概念LSP，额，当然不是老色批🤣  LSP（Language Server Protocol）开源的语言服务器协定。由RedHat、Microsoft和 Codenvy 联合推出，可以让不同的程序编辑器与集成开发环境（IDE）方便嵌入各种程序语言，允许开发人员在最喜爱的工具中使用各种语言来撰写程序  而C++的LSP有  ms-vscode.cpptools clangd cc">
<meta property="og:type" content="article">
<meta property="og:title" content="在vscode上使用clangd">
<meta property="og:url" content="http://example.com/2022/03/28/%E5%9C%A8vscode%E4%B8%8A%E4%BD%BF%E7%94%A8clangd/index.html">
<meta property="og:site_name" content="F7kyyy的博客">
<meta property="og:description" content="首先我们先明白一个概念LSP，额，当然不是老色批🤣  LSP（Language Server Protocol）开源的语言服务器协定。由RedHat、Microsoft和 Codenvy 联合推出，可以让不同的程序编辑器与集成开发环境（IDE）方便嵌入各种程序语言，允许开发人员在最喜爱的工具中使用各种语言来撰写程序  而C++的LSP有  ms-vscode.cpptools clangd cc">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://example.com/img/article/vscode.png">
<meta property="article:published_time" content="2022-03-28T02:19:38.000Z">
<meta property="article:modified_time" content="2023-07-09T13:47:12.000Z">
<meta property="article:author" content="Feng Zikai">
<meta property="article:tag" content="环境配置">
<meta property="article:tag" content="C++">
<meta property="article:tag" content="Visual Studio Code">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="http://example.com/img/article/vscode.png">
  
  
  
  <title>在vscode上使用clangd - F7kyyy的博客</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  



  
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css">



  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.5-a","typing":{"enable":true,"typeSpeed":60,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading1.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":{"measurement_id":null},"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml","include_content_in_search":true};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>F7kyyy&#39;s blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/">
                <i class="iconfont icon-link-fill"></i>
                <span>友链</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="在vscode上使用clangd"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-03-28 10:19" pubdate>
          2022年3月28日 上午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          47k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          391 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <h1 id="seo-header">在vscode上使用clangd</h1>
            
            
              <div class="markdown-body">
                
                <p>首先我们先明白一个概念LSP，额，当然不是老色批🤣</p>
<blockquote>
<p>LSP（Language Server Protocol）开源的语言服务器协定。由RedHat、Microsoft和 Codenvy 联合推出，可以让不同的程序编辑器与集成开发环境（IDE）方便嵌入各种程序语言，允许开发人员在最喜爱的工具中使用各种语言来撰写程序</p>
</blockquote>
<p>而C++的LSP有</p>
<ul>
<li>ms-vscode.cpptools</li>
<li>clangd</li>
<li>ccls</li>
</ul>
<p>visual studio code 中微软官方的C&#x2F;C++插件使用的是第一个，经常出现各种各样的问题，同时代码补全不是跟好用，例如C++ STL 在使用时无法使用括号补全。同时经常出现更新不及时，更改代码前出现的报错有时需要重新打开项目才会消失:cry:,就很烦，所以这里使用官方推荐的clangd插件进行C&#x2F;C++补全，静态检查，高亮功能。</p>
<h2 id="1-备份原有的配置文件"><a href="#1-备份原有的配置文件" class="headerlink" title="1. 备份原有的配置文件"></a>1. 备份原有的配置文件</h2><p>在Windows 10上使用 C&#x2F;C++调试时默认会自动生成<code>task.json</code>和<code>launch.json</code>文件，但有的时候会抽风无法生成<code>launch.json</code>，这里做一个备份，基本上官方配置复制下来更改一下安装的工具链地址就可以用：<a target="_blank" rel="noopener" href="https://code.visualstudio.com/docs/cpp/config-mingw">配置地址</a>，我做了一些个性化配置。</p>
<p><strong>task.json 相当于输入一段g++命令，对一段C++代码进行编译和执行，launch.json 会每次调用tasks.json</strong></p>
<p>使用这个配置可以在调试的时候自动聚焦到终端，生成的二进制文件会出现在根目录的build文件夹</p>
<ul>
<li><code>task.json</code></li>
</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-punctuation">&#123;</span><br>    <span class="hljs-attr">&quot;tasks&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>        <span class="hljs-punctuation">&#123;</span><br>            <span class="hljs-attr">&quot;type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;cppbuild&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;label&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;C/C++: build active file&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;command&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;C:\\Users\\FengisZZZ\\ServerTools\\mingw64\\bin\\g++.exe&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;args&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>                <span class="hljs-string">&quot;-std=c++20&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;-fdiagnostics-color=always&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;-g&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;$&#123;file&#125;&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;-o&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;\\build\\$&#123;fileBasenameNoExtension&#125;.exe&quot;</span><br>            <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;options&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>                <span class="hljs-attr">&quot;cwd&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;&quot;</span><br>            <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;problemMatcher&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>                <span class="hljs-string">&quot;$gcc&quot;</span><br>            <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;group&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>                <span class="hljs-attr">&quot;kind&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;build&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-attr">&quot;isDefault&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><br>            <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;detail&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;调试器生成的任务。&quot;</span><br>        <span class="hljs-punctuation">&#125;</span><br>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-attr">&quot;version&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;2.0.0&quot;</span><br><span class="hljs-punctuation">&#125;</span><br></code></pre></td></tr></table></figure>

<ul>
<li><code>launch.json</code></li>
</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-punctuation">&#123;</span><br>    <span class="hljs-attr">&quot;version&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;0.2.0&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-attr">&quot;configurations&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>        <span class="hljs-punctuation">&#123;</span><br>            <span class="hljs-attr">&quot;name&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;Debug&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;cppdbg&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;request&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;launch&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;program&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;\\build\\$&#123;fileBasenameNoExtension&#125;.exe&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;args&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;stopAtEntry&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;cwd&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;environment&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;externalConsole&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;internalConsoleOptions&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;neverOpen&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;MIMode&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;gdb&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;miDebuggerPath&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;C:\\Users\\FengisZZZ\\ServerTools\\mingw64\\bin\\gdb.exe&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;setupCommands&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>                <span class="hljs-punctuation">&#123;</span><br>                    <span class="hljs-attr">&quot;description&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;Enable pretty-printing for gdb&quot;</span><span class="hljs-punctuation">,</span><br>                    <span class="hljs-attr">&quot;text&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;-enable-pretty-printing&quot;</span><span class="hljs-punctuation">,</span><br>                    <span class="hljs-attr">&quot;ignoreFailures&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><br>                <span class="hljs-punctuation">&#125;</span><br>            <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;preLaunchTask&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;C/C++: build active file&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-punctuation">&#125;</span><br>    <span class="hljs-punctuation">]</span><br><span class="hljs-punctuation">&#125;</span><br></code></pre></td></tr></table></figure>

<h2 id="2-在Ubuntu中设置"><a href="#2-在Ubuntu中设置" class="headerlink" title="2. 在Ubuntu中设置"></a>2. 在Ubuntu中设置</h2><h3 id="2-1-安装包"><a href="#2-1-安装包" class="headerlink" title="2.1 安装包"></a>2.1 安装包</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs bash">sudo apt update<br>sudo apt install g++ gcc gdb cmake make llvm clangd lldb<br></code></pre></td></tr></table></figure>

<h3 id="2-2-安装vscode-插件"><a href="#2-2-安装vscode-插件" class="headerlink" title="2.2 安装vscode 插件"></a>2.2 安装vscode 插件</h3><p><img src="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/202203281106759.png" srcset="/img/loading1.gif" lazyload alt="image-20220328110618664"></p>
<p>在安装C&#x2F;C++和clangd插件后，会出现<strong>冲突问题</strong>，是两个插件补全出现冲突，在<code>setting.json</code>中添加，关闭自动补全</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-comment">// 只第一个其实就可以</span><br><span class="hljs-attr">&quot;C_Cpp.intelliSenseEngine&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;Disabled&quot;</span><span class="hljs-punctuation">,</span><br><span class="hljs-attr">&quot;C_Cpp.autocomplete&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;Disabled&quot;</span><span class="hljs-punctuation">,</span><br><span class="hljs-attr">&quot;C_Cpp.errorSquiggles&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;Disabled&quot;</span><span class="hljs-punctuation">,</span><br></code></pre></td></tr></table></figure>

<h3 id="2-3-使用clang-lldb"><a href="#2-3-使用clang-lldb" class="headerlink" title="2.3 使用clang++,lldb"></a>2.3 使用clang++,lldb</h3><p>配置方法与正常的配置差不多，有些许修改，需要注意在linux下，二进制文件没有“.exe后缀”</p>
<ul>
<li><code> tasks.json</code></li>
</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-punctuation">&#123;</span><br>    <span class="hljs-attr">&quot;tasks&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>        <span class="hljs-punctuation">&#123;</span><br>            <span class="hljs-attr">&quot;type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;shell&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;label&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;C/C++: build active file&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;command&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;/usr/bin/clang++&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;args&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>                <span class="hljs-string">&quot;-std=c++20&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;-fdiagnostics-color=always&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;-g&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;$&#123;file&#125;&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;-o&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;/build/$&#123;fileBasenameNoExtension&#125;&quot;</span><br>            <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;options&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>                <span class="hljs-attr">&quot;cwd&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;&quot;</span><br>            <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;group&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>                <span class="hljs-attr">&quot;kind&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;build&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-attr">&quot;isDefault&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><br>            <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;detail&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;调试器生成的任务。&quot;</span><br>        <span class="hljs-punctuation">&#125;</span><br>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-attr">&quot;version&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;2.0.0&quot;</span><br><span class="hljs-punctuation">&#125;</span><br></code></pre></td></tr></table></figure>

<ul>
<li><code>launch.json</code></li>
</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-punctuation">&#123;</span><br>    <span class="hljs-comment">// 使用 IntelliSense 了解相关属性。 </span><br>    <span class="hljs-comment">// 悬停以查看现有属性的描述。</span><br>    <span class="hljs-comment">// 欲了解更多信息，请访问: https://go.microsoft.com/fwlink/?linkid=830387</span><br>    <span class="hljs-attr">&quot;version&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;0.2.0&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-attr">&quot;configurations&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>        <span class="hljs-punctuation">&#123;</span><br>            <span class="hljs-attr">&quot;type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;lldb&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;request&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;launch&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;name&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;Debug&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;program&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;/build/$&#123;fileBasenameNoExtension&#125;&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;args&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;stopAtEntry&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;cwd&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;environment&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;externalConsole&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;internalConsoleOptions&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;neverOpen&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;preLaunchTask&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;C/C++: build active file&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-punctuation">&#125;</span><br>    <span class="hljs-punctuation">]</span><br><span class="hljs-punctuation">&#125;</span><br></code></pre></td></tr></table></figure>

<h3 id="2-4-使用g-gdb"><a href="#2-4-使用g-gdb" class="headerlink" title="2.4 使用g++,gdb"></a>2.4 使用g++,gdb</h3><p>因为我们只关闭了C&#x2F;C++插件的自动补全功能，所以理论上我们是可以使用官方插件进行调试的，使用clangd写代码，C&#x2F;C++调试。官方的插件在调试上对内存断点上更加好用</p>
<p><img src="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/202203281657632.png" srcset="/img/loading1.gif" lazyload alt="image-20220328165732579"></p>
<p><code>tasks.json</code></p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-punctuation">&#123;</span><br>    <span class="hljs-attr">&quot;version&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;2.0.0&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-attr">&quot;tasks&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>        <span class="hljs-punctuation">&#123;</span><br>            <span class="hljs-attr">&quot;type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;shell&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;label&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;g++ build active file&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;command&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;/usr/bin/g++&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;args&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>                <span class="hljs-string">&quot;-g&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;$&#123;file&#125;&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;-o&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;/build/$&#123;fileBasenameNoExtension&#125;&quot;</span><br>            <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;options&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>                <span class="hljs-attr">&quot;cwd&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;/usr/bin&quot;</span><br>            <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;problemMatcher&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>                <span class="hljs-string">&quot;$gcc&quot;</span><br>            <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;group&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>                <span class="hljs-attr">&quot;kind&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;build&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-attr">&quot;isDefault&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><br>            <span class="hljs-punctuation">&#125;</span><br>        <span class="hljs-punctuation">&#125;</span><br>    <span class="hljs-punctuation">]</span><br><span class="hljs-punctuation">&#125;</span><br></code></pre></td></tr></table></figure>

<p><code>launch.json</code></p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-punctuation">&#123;</span><br>    <span class="hljs-attr">&quot;version&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;0.2.0&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-attr">&quot;configurations&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>        <span class="hljs-punctuation">&#123;</span><br>            <span class="hljs-attr">&quot;name&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;DEBUG&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;cppdbg&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;request&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;launch&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;program&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;/build/$&#123;fileBasenameNoExtension&#125;&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;args&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;stopAtEntry&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;cwd&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;environment&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;externalConsole&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;MIMode&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;gdb&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;internalConsoleOptions&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;neverOpen&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;setupCommands&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>                <span class="hljs-punctuation">&#123;</span><br>                    <span class="hljs-attr">&quot;description&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;Enable pretty-printing for gdb&quot;</span><span class="hljs-punctuation">,</span><br>                    <span class="hljs-attr">&quot;text&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;-enable-pretty-printing&quot;</span><span class="hljs-punctuation">,</span><br>                    <span class="hljs-attr">&quot;ignoreFailures&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><br>                <span class="hljs-punctuation">&#125;</span><br>            <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;preLaunchTask&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;g++ build active file&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;miDebuggerPath&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;/usr/bin/gdb&quot;</span><br>        <span class="hljs-punctuation">&#125;</span><br>    <span class="hljs-punctuation">]</span><br><span class="hljs-punctuation">&#125;</span><br></code></pre></td></tr></table></figure>

<p>由于编译和调试所依赖的工具和插件是不同的，我甚至可以使用clang++编译，gdb调试，只需要将<code>tasks.json</code>的内容更换为使用clang++时即可</p>
<h3 id="2-5-使用Cmake进行多文件编译"><a href="#2-5-使用Cmake进行多文件编译" class="headerlink" title="2.5 使用Cmake进行多文件编译"></a>2.5 使用Cmake进行多文件编译</h3><p>打开一个CMake项目，这是一个简单的项目，只有一个头文件和源文件构成</p>
<p><img src="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/202203282106596.png" srcset="/img/loading1.gif" lazyload alt="image-20220328210628497"></p>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs cmake"><span class="hljs-keyword">cmake_minimum_required</span>(VERSION <span class="hljs-number">3.0</span>.<span class="hljs-number">0</span>)<br><span class="hljs-keyword">project</span>(CppClangd)<br><span class="hljs-keyword">set</span>(CMAKE_CXX_STANDARD <span class="hljs-number">20</span>)<br><span class="hljs-keyword">set</span>(CMAKE_EXPORT_COMPILE_COMMANDS <span class="hljs-keyword">ON</span>)<br><span class="hljs-keyword">add_executable</span>(CppClangd  main.cpp  MyFunction.h)<br></code></pre></td></tr></table></figure>

<h4 id="2-5-1-生成compile-command-json"><a href="#2-5-1-生成compile-command-json" class="headerlink" title="2.5.1 生成compile_command.json"></a>2.5.1 生成compile_command.json</h4><p>clangd需要根据该文件获取各个文件的include path，以及编译警告错误之类的，必须要有这个文件</p>
<ul>
<li>在CMakeList.txt中添加即可</li>
</ul>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs cmake"><span class="hljs-keyword">set</span>(CMAKE_EXPORT_COMPILE_COMMANDS <span class="hljs-keyword">ON</span>)<br></code></pre></td></tr></table></figure>

<ul>
<li>在build目录下</li>
</ul>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs cmake">cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=YES .<br></code></pre></td></tr></table></figure>



<h4 id="2-5-2-Debug配置"><a href="#2-5-2-Debug配置" class="headerlink" title="2.5.2 Debug配置"></a>2.5.2 Debug配置</h4><p>实际上，由于我们因为只禁用了C&#x2F;C++的自动补全功能(再次强调:laughing:),所以正常来讲可以忽略这个东西，但是如果完全不用官方这一套的话，还是需要的。我们只需要调试，所以只需要launch.json,将我们之前的launch.json根据<a target="_blank" rel="noopener" href="https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/debug-launch.md#debug-using-a-launchjson-file">Cmake Tools</a>官方文档改一改就可以了</p>
<ul>
<li>使用gdb</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><code class="hljs bash">&#123;<br>    <span class="hljs-string">&quot;version&quot;</span>: <span class="hljs-string">&quot;0.2.0&quot;</span>,<br>    <span class="hljs-string">&quot;configurations&quot;</span>: [<br>        &#123;<br>            <span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-string">&quot;DEBUG&quot;</span>,<br>            <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;cppdbg&quot;</span>,<br>            <span class="hljs-string">&quot;request&quot;</span>: <span class="hljs-string">&quot;launch&quot;</span>,<br>            <span class="hljs-string">&quot;program&quot;</span>: <span class="hljs-string">&quot;<span class="hljs-variable">$&#123;command:cmake.launchTargetPath&#125;</span>&quot;</span>,<br>            <span class="hljs-string">&quot;args&quot;</span>: [],<br>            <span class="hljs-string">&quot;stopAtEntry&quot;</span>: <span class="hljs-literal">false</span>,<br>            <span class="hljs-string">&quot;cwd&quot;</span>: <span class="hljs-string">&quot;<span class="hljs-variable">$&#123;workspaceFolder&#125;</span>&quot;</span>,<br>            <span class="hljs-string">&quot;environment&quot;</span>: [],<br>            <span class="hljs-string">&quot;externalConsole&quot;</span>: <span class="hljs-literal">false</span>,<br>            <span class="hljs-string">&quot;internalConsoleOptions&quot;</span>: <span class="hljs-string">&quot;neverOpen&quot;</span>,<br>            <span class="hljs-string">&quot;MIMode&quot;</span>: <span class="hljs-string">&quot;gdb&quot;</span>,<br>            <span class="hljs-string">&quot;setupCommands&quot;</span>: [<br>                &#123;<br>                    <span class="hljs-string">&quot;description&quot;</span>: <span class="hljs-string">&quot;Enable pretty-printing for gdb&quot;</span>,<br>                    <span class="hljs-string">&quot;text&quot;</span>: <span class="hljs-string">&quot;-enable-pretty-printing&quot;</span>,<br>                    <span class="hljs-string">&quot;ignoreFailures&quot;</span>: <span class="hljs-literal">true</span><br>                &#125;<br>            ],<br>            <span class="hljs-string">&quot;miDebuggerPath&quot;</span>: <span class="hljs-string">&quot;/usr/bin/gdb&quot;</span><br>        &#125;<br>    ]<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li>使用lldb</li>
</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-punctuation">&#123;</span><br>    <span class="hljs-comment">// 使用 IntelliSense 了解相关属性。 </span><br>    <span class="hljs-comment">// 悬停以查看现有属性的描述。</span><br>    <span class="hljs-comment">// 欲了解更多信息，请访问: https://go.microsoft.com/fwlink/?linkid=830387</span><br>    <span class="hljs-attr">&quot;version&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;0.2.0&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-attr">&quot;configurations&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>        <span class="hljs-punctuation">&#123;</span><br>            <span class="hljs-attr">&quot;type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;lldb&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;request&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;launch&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;name&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;Debug&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;program&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;command:cmake.launchTargetPath&#125;&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;args&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;stopAtEntry&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;cwd&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;environment&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;externalConsole&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;internalConsoleOptions&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;neverOpen&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-punctuation">&#125;</span><br>    <span class="hljs-punctuation">]</span><br><span class="hljs-punctuation">&#125;</span><br></code></pre></td></tr></table></figure>



<h2 id="3-配置clangd"><a href="#3-配置clangd" class="headerlink" title="3. 配置clangd"></a>3. 配置clangd</h2><h3 id="3-1-setting-json"><a href="#3-1-setting-json" class="headerlink" title="3.1 setting.json"></a>3.1 setting.json</h3><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-attr">&quot;clangd.arguments&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>        <span class="hljs-string">&quot; --compile-commands-dir=$&#123;workspaceFold&#125;$/build&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-comment">// clangd在创建索引使用的线程数</span><br>        <span class="hljs-string">&quot;-j=4&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-comment">// 启用 Clang-Tidy 以提供静态检查</span><br>        <span class="hljs-string">&quot;--clang-tidy&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-comment">// 建议风格：重载函数只会给出一个建议；反可以设置为detailed</span><br>        <span class="hljs-string">&quot;--completion-style=bundled&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-comment">// 启用,补全函数时，将会给参数提供占位符</span><br>        <span class="hljs-string">&quot;--function-arg-placeholders=false&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-comment">// 输入建议中，已包含头文件的项与还未包含头文件的项会以圆点加以区分</span><br>        <span class="hljs-string">&quot;--header-insertion-decorators&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-comment">// 补充头文件</span><br>        <span class="hljs-string">&quot;--header-insertion=iwyu&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-comment">// 让 Clangd 生成更详细的日志</span><br>        <span class="hljs-string">&quot;--log=verbose&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-comment">// pch存储在内存中，内存消耗更大，但是性能更优</span><br>        <span class="hljs-string">&quot;--pch-storage=memory&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-comment">// 输出的 JSON 文件更美观</span><br>        <span class="hljs-string">&quot;--pretty&quot;</span><span class="hljs-punctuation">,</span><br>    	<span class="hljs-comment">// 设置项目，或者用户config</span><br>    	<span class="hljs-string">&quot;--enable-config&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br><br><span class="hljs-comment">// LLDB 指针显示解引用内容</span><br><span class="hljs-attr">&quot;lldb.dereferencePointers&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span><br><span class="hljs-comment">// LLDB 鼠标悬停在变量上时预览变量值</span><br><span class="hljs-attr">&quot;lldb.evaluateForHovers&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span><br><span class="hljs-comment">// LLDB 监视表达式的默认类型</span><br><span class="hljs-attr">&quot;lldb.launch.expressions&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;simple&quot;</span><span class="hljs-punctuation">,</span><br><span class="hljs-comment">// LLDB 不显示汇编代码</span><br><span class="hljs-attr">&quot;lldb.showDisassembly&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;never&quot;</span><span class="hljs-punctuation">,</span><br><span class="hljs-comment">// LLDB 生成更详细的日志</span><br><span class="hljs-attr">&quot;lldb.verboseLogging&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span><br><br><span class="hljs-comment">// 保存 cmake.sourceDirectory 或 CMakeLists.txt 内容时，不自动配置 CMake 项目目录</span><br><span class="hljs-attr">&quot;cmake.configureOnEdit&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span><br><span class="hljs-comment">// 在 CMake 项目目录打开时自动对其进行配置</span><br><span class="hljs-attr">&quot;cmake.configureOnOpen&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span><br><span class="hljs-comment">// 成功配置后，将 compile_commands.json 复制到此位置</span><br><span class="hljs-attr">&quot;cmake.copyCompileCommands&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;&quot;</span><span class="hljs-punctuation">,</span><br></code></pre></td></tr></table></figure>

<h3 id="3-2-clang-tidy"><a href="#3-2-clang-tidy" class="headerlink" title="3.2 .clang-tidy"></a>3.2 .clang-tidy</h3><p><code>Ctrl+Shft+p</code>配置如下内容,<a target="_blank" rel="noopener" href="https://clangd.llvm.org/config.html">官网配置</a></p>
<p><img src="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/202203282252474.png" srcset="/img/loading1.gif" lazyload alt="image-20220328225226433"></p>
<h4 id="3-2-1-配置含义"><a href="#3-2-1-配置含义" class="headerlink" title="3.2.1 配置含义"></a>3.2.1 配置含义</h4><p>可能官网配置较为繁琐，这里列举了大部分的中文含义和示例代码</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br><span class="line">401</span><br><span class="line">402</span><br><span class="line">403</span><br><span class="line">404</span><br><span class="line">405</span><br><span class="line">406</span><br><span class="line">407</span><br><span class="line">408</span><br><span class="line">409</span><br><span class="line">410</span><br><span class="line">411</span><br><span class="line">412</span><br><span class="line">413</span><br><span class="line">414</span><br><span class="line">415</span><br><span class="line">416</span><br><span class="line">417</span><br><span class="line">418</span><br><span class="line">419</span><br><span class="line">420</span><br><span class="line">421</span><br><span class="line">422</span><br><span class="line">423</span><br><span class="line">424</span><br><span class="line">425</span><br><span class="line">426</span><br><span class="line">427</span><br><span class="line">428</span><br><span class="line">429</span><br><span class="line">430</span><br><span class="line">431</span><br><span class="line">432</span><br><span class="line">433</span><br><span class="line">434</span><br><span class="line">435</span><br><span class="line">436</span><br><span class="line">437</span><br><span class="line">438</span><br><span class="line">439</span><br><span class="line">440</span><br><span class="line">441</span><br><span class="line">442</span><br><span class="line">443</span><br><span class="line">444</span><br><span class="line">445</span><br><span class="line">446</span><br><span class="line">447</span><br><span class="line">448</span><br><span class="line">449</span><br><span class="line">450</span><br><span class="line">451</span><br><span class="line">452</span><br><span class="line">453</span><br><span class="line">454</span><br><span class="line">455</span><br><span class="line">456</span><br><span class="line">457</span><br><span class="line">458</span><br><span class="line">459</span><br><span class="line">460</span><br><span class="line">461</span><br><span class="line">462</span><br><span class="line">463</span><br><span class="line">464</span><br><span class="line">465</span><br><span class="line">466</span><br><span class="line">467</span><br><span class="line">468</span><br><span class="line">469</span><br><span class="line">470</span><br><span class="line">471</span><br><span class="line">472</span><br><span class="line">473</span><br><span class="line">474</span><br><span class="line">475</span><br><span class="line">476</span><br><span class="line">477</span><br><span class="line">478</span><br><span class="line">479</span><br><span class="line">480</span><br><span class="line">481</span><br><span class="line">482</span><br><span class="line">483</span><br><span class="line">484</span><br><span class="line">485</span><br><span class="line">486</span><br><span class="line">487</span><br><span class="line">488</span><br><span class="line">489</span><br><span class="line">490</span><br><span class="line">491</span><br><span class="line">492</span><br><span class="line">493</span><br><span class="line">494</span><br><span class="line">495</span><br><span class="line">496</span><br><span class="line">497</span><br><span class="line">498</span><br><span class="line">499</span><br><span class="line">500</span><br><span class="line">501</span><br><span class="line">502</span><br><span class="line">503</span><br><span class="line">504</span><br><span class="line">505</span><br><span class="line">506</span><br><span class="line">507</span><br><span class="line">508</span><br><span class="line">509</span><br><span class="line">510</span><br><span class="line">511</span><br><span class="line">512</span><br><span class="line">513</span><br><span class="line">514</span><br><span class="line">515</span><br><span class="line">516</span><br><span class="line">517</span><br><span class="line">518</span><br><span class="line">519</span><br><span class="line">520</span><br><span class="line">521</span><br><span class="line">522</span><br><span class="line">523</span><br><span class="line">524</span><br><span class="line">525</span><br><span class="line">526</span><br><span class="line">527</span><br><span class="line">528</span><br><span class="line">529</span><br><span class="line">530</span><br><span class="line">531</span><br><span class="line">532</span><br><span class="line">533</span><br><span class="line">534</span><br><span class="line">535</span><br><span class="line">536</span><br><span class="line">537</span><br><span class="line">538</span><br><span class="line">539</span><br><span class="line">540</span><br><span class="line">541</span><br><span class="line">542</span><br><span class="line">543</span><br><span class="line">544</span><br><span class="line">545</span><br><span class="line">546</span><br><span class="line">547</span><br><span class="line">548</span><br><span class="line">549</span><br><span class="line">550</span><br><span class="line">551</span><br><span class="line">552</span><br><span class="line">553</span><br><span class="line">554</span><br><span class="line">555</span><br><span class="line">556</span><br><span class="line">557</span><br><span class="line">558</span><br><span class="line">559</span><br><span class="line">560</span><br><span class="line">561</span><br><span class="line">562</span><br><span class="line">563</span><br><span class="line">564</span><br><span class="line">565</span><br><span class="line">566</span><br><span class="line">567</span><br><span class="line">568</span><br><span class="line">569</span><br><span class="line">570</span><br><span class="line">571</span><br><span class="line">572</span><br><span class="line">573</span><br><span class="line">574</span><br><span class="line">575</span><br><span class="line">576</span><br><span class="line">577</span><br><span class="line">578</span><br><span class="line">579</span><br><span class="line">580</span><br><span class="line">581</span><br><span class="line">582</span><br><span class="line">583</span><br><span class="line">584</span><br><span class="line">585</span><br><span class="line">586</span><br><span class="line">587</span><br><span class="line">588</span><br><span class="line">589</span><br><span class="line">590</span><br><span class="line">591</span><br><span class="line">592</span><br><span class="line">593</span><br><span class="line">594</span><br><span class="line">595</span><br><span class="line">596</span><br><span class="line">597</span><br><span class="line">598</span><br><span class="line">599</span><br><span class="line">600</span><br><span class="line">601</span><br><span class="line">602</span><br><span class="line">603</span><br><span class="line">604</span><br><span class="line">605</span><br><span class="line">606</span><br><span class="line">607</span><br><span class="line">608</span><br><span class="line">609</span><br><span class="line">610</span><br><span class="line">611</span><br><span class="line">612</span><br><span class="line">613</span><br><span class="line">614</span><br><span class="line">615</span><br><span class="line">616</span><br><span class="line">617</span><br><span class="line">618</span><br><span class="line">619</span><br><span class="line">620</span><br><span class="line">621</span><br><span class="line">622</span><br><span class="line">623</span><br><span class="line">624</span><br><span class="line">625</span><br><span class="line">626</span><br><span class="line">627</span><br><span class="line">628</span><br><span class="line">629</span><br><span class="line">630</span><br><span class="line">631</span><br><span class="line">632</span><br><span class="line">633</span><br><span class="line">634</span><br><span class="line">635</span><br><span class="line">636</span><br><span class="line">637</span><br><span class="line">638</span><br><span class="line">639</span><br><span class="line">640</span><br><span class="line">641</span><br><span class="line">642</span><br><span class="line">643</span><br><span class="line">644</span><br><span class="line">645</span><br><span class="line">646</span><br><span class="line">647</span><br><span class="line">648</span><br><span class="line">649</span><br><span class="line">650</span><br><span class="line">651</span><br><span class="line">652</span><br><span class="line">653</span><br><span class="line">654</span><br><span class="line">655</span><br><span class="line">656</span><br><span class="line">657</span><br><span class="line">658</span><br><span class="line">659</span><br><span class="line">660</span><br><span class="line">661</span><br><span class="line">662</span><br><span class="line">663</span><br><span class="line">664</span><br><span class="line">665</span><br><span class="line">666</span><br><span class="line">667</span><br><span class="line">668</span><br><span class="line">669</span><br><span class="line">670</span><br><span class="line">671</span><br><span class="line">672</span><br><span class="line">673</span><br><span class="line">674</span><br><span class="line">675</span><br><span class="line">676</span><br><span class="line">677</span><br><span class="line">678</span><br><span class="line">679</span><br><span class="line">680</span><br><span class="line">681</span><br><span class="line">682</span><br><span class="line">683</span><br><span class="line">684</span><br><span class="line">685</span><br><span class="line">686</span><br><span class="line">687</span><br><span class="line">688</span><br><span class="line">689</span><br><span class="line">690</span><br><span class="line">691</span><br><span class="line">692</span><br><span class="line">693</span><br><span class="line">694</span><br><span class="line">695</span><br><span class="line">696</span><br><span class="line">697</span><br><span class="line">698</span><br><span class="line">699</span><br><span class="line">700</span><br><span class="line">701</span><br><span class="line">702</span><br><span class="line">703</span><br><span class="line">704</span><br><span class="line">705</span><br><span class="line">706</span><br><span class="line">707</span><br><span class="line">708</span><br><span class="line">709</span><br><span class="line">710</span><br><span class="line">711</span><br><span class="line">712</span><br><span class="line">713</span><br><span class="line">714</span><br><span class="line">715</span><br><span class="line">716</span><br><span class="line">717</span><br><span class="line">718</span><br><span class="line">719</span><br><span class="line">720</span><br><span class="line">721</span><br><span class="line">722</span><br><span class="line">723</span><br><span class="line">724</span><br><span class="line">725</span><br><span class="line">726</span><br><span class="line">727</span><br><span class="line">728</span><br><span class="line">729</span><br><span class="line">730</span><br><span class="line">731</span><br><span class="line">732</span><br><span class="line">733</span><br><span class="line">734</span><br><span class="line">735</span><br><span class="line">736</span><br><span class="line">737</span><br><span class="line">738</span><br><span class="line">739</span><br><span class="line">740</span><br><span class="line">741</span><br><span class="line">742</span><br><span class="line">743</span><br><span class="line">744</span><br><span class="line">745</span><br><span class="line">746</span><br><span class="line">747</span><br><span class="line">748</span><br><span class="line">749</span><br><span class="line">750</span><br><span class="line">751</span><br><span class="line">752</span><br><span class="line">753</span><br><span class="line">754</span><br><span class="line">755</span><br><span class="line">756</span><br><span class="line">757</span><br><span class="line">758</span><br><span class="line">759</span><br><span class="line">760</span><br><span class="line">761</span><br><span class="line">762</span><br><span class="line">763</span><br><span class="line">764</span><br><span class="line">765</span><br><span class="line">766</span><br><span class="line">767</span><br><span class="line">768</span><br><span class="line">769</span><br><span class="line">770</span><br><span class="line">771</span><br><span class="line">772</span><br><span class="line">773</span><br><span class="line">774</span><br><span class="line">775</span><br><span class="line">776</span><br><span class="line">777</span><br><span class="line">778</span><br><span class="line">779</span><br><span class="line">780</span><br><span class="line">781</span><br><span class="line">782</span><br><span class="line">783</span><br><span class="line">784</span><br><span class="line">785</span><br><span class="line">786</span><br><span class="line">787</span><br><span class="line">788</span><br><span class="line">789</span><br><span class="line">790</span><br><span class="line">791</span><br><span class="line">792</span><br><span class="line">793</span><br><span class="line">794</span><br><span class="line">795</span><br><span class="line">796</span><br><span class="line">797</span><br><span class="line">798</span><br><span class="line">799</span><br><span class="line">800</span><br><span class="line">801</span><br><span class="line">802</span><br><span class="line">803</span><br><span class="line">804</span><br><span class="line">805</span><br><span class="line">806</span><br><span class="line">807</span><br><span class="line">808</span><br><span class="line">809</span><br><span class="line">810</span><br><span class="line">811</span><br><span class="line">812</span><br><span class="line">813</span><br><span class="line">814</span><br><span class="line">815</span><br><span class="line">816</span><br><span class="line">817</span><br><span class="line">818</span><br><span class="line">819</span><br><span class="line">820</span><br><span class="line">821</span><br><span class="line">822</span><br><span class="line">823</span><br><span class="line">824</span><br><span class="line">825</span><br><span class="line">826</span><br><span class="line">827</span><br><span class="line">828</span><br><span class="line">829</span><br><span class="line">830</span><br><span class="line">831</span><br><span class="line">832</span><br><span class="line">833</span><br><span class="line">834</span><br><span class="line">835</span><br><span class="line">836</span><br><span class="line">837</span><br><span class="line">838</span><br><span class="line">839</span><br><span class="line">840</span><br><span class="line">841</span><br><span class="line">842</span><br><span class="line">843</span><br><span class="line">844</span><br><span class="line">845</span><br><span class="line">846</span><br><span class="line">847</span><br><span class="line">848</span><br><span class="line">849</span><br><span class="line">850</span><br><span class="line">851</span><br><span class="line">852</span><br><span class="line">853</span><br><span class="line">854</span><br><span class="line">855</span><br><span class="line">856</span><br><span class="line">857</span><br><span class="line">858</span><br><span class="line">859</span><br><span class="line">860</span><br><span class="line">861</span><br><span class="line">862</span><br><span class="line">863</span><br><span class="line">864</span><br><span class="line">865</span><br><span class="line">866</span><br><span class="line">867</span><br><span class="line">868</span><br><span class="line">869</span><br><span class="line">870</span><br><span class="line">871</span><br><span class="line">872</span><br><span class="line">873</span><br><span class="line">874</span><br><span class="line">875</span><br><span class="line">876</span><br><span class="line">877</span><br><span class="line">878</span><br><span class="line">879</span><br><span class="line">880</span><br><span class="line">881</span><br><span class="line">882</span><br><span class="line">883</span><br><span class="line">884</span><br><span class="line">885</span><br><span class="line">886</span><br><span class="line">887</span><br><span class="line">888</span><br><span class="line">889</span><br><span class="line">890</span><br><span class="line">891</span><br><span class="line">892</span><br><span class="line">893</span><br><span class="line">894</span><br><span class="line">895</span><br><span class="line">896</span><br><span class="line">897</span><br><span class="line">898</span><br><span class="line">899</span><br><span class="line">900</span><br><span class="line">901</span><br><span class="line">902</span><br><span class="line">903</span><br><span class="line">904</span><br><span class="line">905</span><br><span class="line">906</span><br><span class="line">907</span><br><span class="line">908</span><br><span class="line">909</span><br><span class="line">910</span><br><span class="line">911</span><br><span class="line">912</span><br><span class="line">913</span><br><span class="line">914</span><br><span class="line">915</span><br><span class="line">916</span><br><span class="line">917</span><br><span class="line">918</span><br><span class="line">919</span><br><span class="line">920</span><br><span class="line">921</span><br><span class="line">922</span><br><span class="line">923</span><br><span class="line">924</span><br><span class="line">925</span><br><span class="line">926</span><br><span class="line">927</span><br><span class="line">928</span><br><span class="line">929</span><br><span class="line">930</span><br><span class="line">931</span><br><span class="line">932</span><br><span class="line">933</span><br><span class="line">934</span><br><span class="line">935</span><br><span class="line">936</span><br><span class="line">937</span><br><span class="line">938</span><br><span class="line">939</span><br><span class="line">940</span><br><span class="line">941</span><br><span class="line">942</span><br><span class="line">943</span><br><span class="line">944</span><br><span class="line">945</span><br><span class="line">946</span><br><span class="line">947</span><br><span class="line">948</span><br><span class="line">949</span><br><span class="line">950</span><br><span class="line">951</span><br><span class="line">952</span><br><span class="line">953</span><br><span class="line">954</span><br><span class="line">955</span><br><span class="line">956</span><br><span class="line">957</span><br><span class="line">958</span><br><span class="line">959</span><br><span class="line">960</span><br><span class="line">961</span><br><span class="line">962</span><br><span class="line">963</span><br><span class="line">964</span><br><span class="line">965</span><br><span class="line">966</span><br><span class="line">967</span><br><span class="line">968</span><br><span class="line">969</span><br><span class="line">970</span><br><span class="line">971</span><br><span class="line">972</span><br><span class="line">973</span><br><span class="line">974</span><br><span class="line">975</span><br><span class="line">976</span><br><span class="line">977</span><br><span class="line">978</span><br><span class="line">979</span><br><span class="line">980</span><br><span class="line">981</span><br><span class="line">982</span><br><span class="line">983</span><br><span class="line">984</span><br><span class="line">985</span><br><span class="line">986</span><br><span class="line">987</span><br><span class="line">988</span><br><span class="line">989</span><br><span class="line">990</span><br><span class="line">991</span><br><span class="line">992</span><br><span class="line">993</span><br><span class="line">994</span><br><span class="line">995</span><br><span class="line">996</span><br><span class="line">997</span><br><span class="line">998</span><br><span class="line">999</span><br><span class="line">1000</span><br><span class="line">1001</span><br><span class="line">1002</span><br><span class="line">1003</span><br><span class="line">1004</span><br><span class="line">1005</span><br><span class="line">1006</span><br><span class="line">1007</span><br><span class="line">1008</span><br><span class="line">1009</span><br><span class="line">1010</span><br><span class="line">1011</span><br><span class="line">1012</span><br><span class="line">1013</span><br><span class="line">1014</span><br><span class="line">1015</span><br><span class="line">1016</span><br><span class="line">1017</span><br><span class="line">1018</span><br><span class="line">1019</span><br><span class="line">1020</span><br><span class="line">1021</span><br><span class="line">1022</span><br><span class="line">1023</span><br><span class="line">1024</span><br><span class="line">1025</span><br><span class="line">1026</span><br><span class="line">1027</span><br><span class="line">1028</span><br><span class="line">1029</span><br><span class="line">1030</span><br><span class="line">1031</span><br><span class="line">1032</span><br><span class="line">1033</span><br><span class="line">1034</span><br><span class="line">1035</span><br><span class="line">1036</span><br><span class="line">1037</span><br><span class="line">1038</span><br><span class="line">1039</span><br><span class="line">1040</span><br><span class="line">1041</span><br><span class="line">1042</span><br><span class="line">1043</span><br><span class="line">1044</span><br><span class="line">1045</span><br><span class="line">1046</span><br><span class="line">1047</span><br><span class="line">1048</span><br><span class="line">1049</span><br><span class="line">1050</span><br><span class="line">1051</span><br><span class="line">1052</span><br></pre></td><td class="code"><pre><code class="hljs c++">Checks:<br><span class="hljs-comment">// 从整数类型转换为字符串默认使用std::to_string</span><br><span class="hljs-number">1.</span> boost-use-to-string<br><br><span class="hljs-comment">// 参数注释</span><br><span class="hljs-number">2.</span> bugprone-argument-comment<br><span class="hljs-comment">// before</span><br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">foo</span><span class="hljs-params">(<span class="hljs-type">int</span> MeaningOfLife)</span></span>;<br><span class="hljs-built_in">foo</span>(<span class="hljs-number">42</span>);<br><span class="hljs-comment">// after</span><br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">foo</span><span class="hljs-params">(<span class="hljs-type">int</span> MeaningOfLife)</span></span>;<br><span class="hljs-built_in">foo</span>(<span class="hljs-comment">/*MeaningOfLife=*/</span><span class="hljs-number">42</span>);<br><br><span class="hljs-comment">// 要求相同分支合并</span><br><span class="hljs-number">3.</span> bugprone-branch-clone<br><span class="hljs-comment">// before</span><br><span class="hljs-keyword">switch</span> (ch) &#123;<br><span class="hljs-keyword">case</span> <span class="hljs-string">&#x27;a&#x27;</span>:<br>  <span class="hljs-keyword">return</span> <span class="hljs-number">10</span>;<br><span class="hljs-keyword">case</span> <span class="hljs-string">&#x27;A&#x27;</span>:<br>  <span class="hljs-keyword">return</span> <span class="hljs-number">10</span>;<br><span class="hljs-keyword">default</span>:<br>  <span class="hljs-keyword">return</span> <span class="hljs-number">10</span>;<br>&#125;<br><span class="hljs-comment">// after</span><br><span class="hljs-keyword">switch</span> (ch) &#123;<br><span class="hljs-keyword">case</span> <span class="hljs-string">&#x27;a&#x27;</span>:<br><span class="hljs-keyword">case</span> <span class="hljs-string">&#x27;A&#x27;</span>:<br>  <span class="hljs-keyword">return</span> <span class="hljs-number">10</span>;<br><span class="hljs-keyword">default</span>:<br>  <span class="hljs-keyword">return</span> <span class="hljs-number">10</span>;<br>&#125;<br><br><span class="hljs-keyword">return</span> <span class="hljs-built_in">test_value</span>(x) ? x : x;<br><br><span class="hljs-comment">// 基类拷贝构造函数初始化</span><br><span class="hljs-number">4.</span> bugprone-copy-constructor-init<br><span class="hljs-keyword">class</span> <span class="hljs-title class_">Copyable</span> &#123;<br><span class="hljs-keyword">public</span>:<br>  <span class="hljs-built_in">Copyable</span>() = <span class="hljs-keyword">default</span>;<br>  <span class="hljs-built_in">Copyable</span>(<span class="hljs-type">const</span> Copyable &amp;) = <span class="hljs-keyword">default</span>;<br>&#125;;<br><span class="hljs-keyword">class</span> <span class="hljs-title class_">X2</span> : <span class="hljs-keyword">public</span> Copyable &#123;<br>  <span class="hljs-built_in">X2</span>(<span class="hljs-type">const</span> X2 &amp;other) &#123;&#125; <span class="hljs-comment">// Copyable(other) is missing</span><br>&#125;;<br><span class="hljs-keyword">class</span> <span class="hljs-title class_">X4</span> : <span class="hljs-keyword">public</span> Copyable &#123;<br>  <span class="hljs-built_in">X4</span>(<span class="hljs-type">const</span> X4 &amp;other) : <span class="hljs-built_in">Copyable</span>() &#123;&#125; <span class="hljs-comment">// other is missing</span><br>&#125;;<br><br><span class="hljs-comment">// 禁止返回动态初始化的静态变量</span><br><span class="hljs-number">5.</span> bugprone-dynamic-<span class="hljs-type">static</span>-<span class="hljs-function">initializers</span><br><span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">foo</span><span class="hljs-params">()</span> </span>&#123;<br>  <span class="hljs-type">static</span> <span class="hljs-type">int</span> k = <span class="hljs-built_in">bar</span>();<br>  <span class="hljs-keyword">return</span> k;<br>&#125;<br><br><span class="hljs-comment">// 禁止在一些函数内抛出异常，避免带来一些风险（析构函数、移动构造函数、移动赋值运算符、main函数、swap函数等）</span><br><span class="hljs-number">6.</span> bugprone-exception-escape<br><br><span class="hljs-comment">// 检查截断和溢出的情况</span><br><span class="hljs-number">7.</span> bugprone-fold-init-type<br><span class="hljs-keyword">auto</span> a = &#123;<span class="hljs-number">0.5f</span>, <span class="hljs-number">0.5f</span>, <span class="hljs-number">0.5f</span>, <span class="hljs-number">0.5f</span>&#125;;<br><span class="hljs-keyword">return</span> std::<span class="hljs-built_in">accumulate</span>(std::<span class="hljs-built_in">begin</span>(a), std::<span class="hljs-built_in">end</span>(a), <span class="hljs-number">0</span>);<br><span class="hljs-keyword">auto</span> a = &#123;<span class="hljs-number">65536LL</span> * <span class="hljs-number">65536</span> * <span class="hljs-number">65536</span>&#125;;<br><span class="hljs-keyword">return</span> std::<span class="hljs-built_in">accumulate</span>(std::<span class="hljs-built_in">begin</span>(a), std::<span class="hljs-built_in">end</span>(a), <span class="hljs-number">0</span>);<br><br><span class="hljs-comment">// 检查同名但未定义的命名空间</span><br><span class="hljs-number">8.</span> bugprone-forward-declaration-<span class="hljs-keyword">namespace</span><br><span class="hljs-keyword">namespace</span> na &#123; <span class="hljs-keyword">struct</span> <span class="hljs-title class_">A</span>; &#125;<br><span class="hljs-keyword">namespace</span> nb &#123; <span class="hljs-keyword">struct</span> <span class="hljs-title class_">A</span> &#123;&#125;; &#125;<br>nb::A a;<br><br><span class="hljs-comment">// 排除不正确舍入问题</span><br><span class="hljs-number">9.</span> bugprone-incorrect-<span class="hljs-built_in">roundings</span><br>(<span class="hljs-type">int</span>)(double_expression + <span class="hljs-number">0.5</span>)<br><br><span class="hljs-comment">// 检查容易出错的无限循环</span><br><span class="hljs-number">10.</span> bugprone-infinite-loop<br><br><span class="hljs-comment">// 检查会导致精度损失的整数除法</span><br><span class="hljs-number">11.</span> bugprone-integer-division<br><br><span class="hljs-comment">// 查找由于缺少括号而可能具有意外行为的宏</span><br><span class="hljs-number">12.</span> bugprone-macro-parentheses<br><br><span class="hljs-comment">// 检查字符串操作的不当行为</span><br><span class="hljs-number">13.</span> bugprone-misplaced-<span class="hljs-keyword">operator</span>-in-strlen-in-alloc<br><br><span class="hljs-comment">// 检查错误的指针动态分配内存</span><br><span class="hljs-number">14.</span> bugprone-misplaced-pointer-arithmetic-in-alloc<br><span class="hljs-comment">// before</span><br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">bad_malloc</span><span class="hljs-params">(<span class="hljs-type">int</span> n)</span> </span>&#123;<br>  <span class="hljs-type">char</span> *p = (<span class="hljs-type">char</span>*) <span class="hljs-built_in">malloc</span>(n) + <span class="hljs-number">10</span>;<br>&#125;<br><span class="hljs-comment">// after</span><br><span class="hljs-type">char</span> *p = (<span class="hljs-type">char</span>*) <span class="hljs-built_in">malloc</span>(n + <span class="hljs-number">10</span>);<br><br><span class="hljs-comment">// 类型转换造成的精度损失</span><br><span class="hljs-number">15.</span> bugprone-misplaced-widening-cast<br><span class="hljs-comment">// before</span><br><span class="hljs-keyword">return</span> (<span class="hljs-type">long</span>)(x * <span class="hljs-number">1000</span>);<br><span class="hljs-comment">// after</span><br><span class="hljs-keyword">return</span> (<span class="hljs-type">long</span>)x * <span class="hljs-number">1000</span>;<br><br><span class="hljs-comment">// 检查std::move()的错误使用</span><br><span class="hljs-number">16.</span> bugprone-move-forwarding-reference<br><br><span class="hljs-comment">// 检查多语句宏定义</span><br><span class="hljs-number">17.</span> bugprone-multiple-statement-macro<br><span class="hljs-meta">#<span class="hljs-keyword">define</span> INCREMENT_TWO(x, y) (x)++; (y)++</span><br><span class="hljs-keyword">if</span> (do_increment)<br>  <span class="hljs-built_in">INCREMENT_TWO</span>(a, b);  <span class="hljs-comment">// (b)++ will be executed unconditionally.</span><br><br><span class="hljs-comment">// 查找容易出错的noescape</span><br><span class="hljs-number">18.</span> bugprone-no-<span class="hljs-function">escape</span><br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">foo</span><span class="hljs-params">(__attribute__((noescape)) <span class="hljs-type">int</span> *p)</span> </span>&#123;<br>  <span class="hljs-built_in">dispatch_async</span>(queue, ^&#123;<br>    *p = <span class="hljs-number">123</span>;<br>  &#125;);<br>&#125;;<br><br><span class="hljs-comment">// 检查可能导致非空终止结果的函数调用，使用strcpy()、strncpy()、strcpy_s()、 strncpy_s()代替memcpy()和memcpy_s()</span><br><span class="hljs-number">19.</span> bugprone-<span class="hljs-keyword">not</span>-null-terminated-<span class="hljs-function">result</span><br><span class="hljs-function"><span class="hljs-type">static</span> <span class="hljs-type">char</span> *<span class="hljs-title">stringCpy</span><span class="hljs-params">(<span class="hljs-type">const</span> std::string &amp;str)</span> </span>&#123;<br>  <span class="hljs-type">char</span> *result = <span class="hljs-built_in">reinterpret_cast</span>&lt;<span class="hljs-type">char</span> *&gt;(<span class="hljs-built_in">malloc</span>(str.<span class="hljs-built_in">size</span>()));<br>  <span class="hljs-built_in">memcpy</span>(result, str.<span class="hljs-built_in">data</span>(), str.<span class="hljs-built_in">size</span>());<br>  <span class="hljs-keyword">return</span> result;<br>&#125;<br><span class="hljs-function"><span class="hljs-type">static</span> <span class="hljs-type">char</span> *<span class="hljs-title">stringCpy</span><span class="hljs-params">(<span class="hljs-type">const</span> std::string &amp;str)</span> </span>&#123;<br>  <span class="hljs-type">char</span> *result = <span class="hljs-built_in">reinterpret_cast</span>&lt;<span class="hljs-type">char</span> *&gt;(<span class="hljs-built_in">malloc</span>(str.<span class="hljs-built_in">size</span>() + <span class="hljs-number">1</span>));<br>  <span class="hljs-built_in">strcpy</span>(result, str.<span class="hljs-built_in">data</span>());<br>  <span class="hljs-keyword">return</span> result;<br>&#125;<br><br><span class="hljs-comment">// 检查对父虚函数的调用</span><br><span class="hljs-number">20.</span> bugprone-parent-<span class="hljs-keyword">virtual</span>-call<br><span class="hljs-keyword">struct</span> <span class="hljs-title class_">A</span> &#123;<br>  <span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-keyword">virtual</span> <span class="hljs-title">foo</span><span class="hljs-params">()</span> </span>&#123;...&#125;<br>&#125;;<br><span class="hljs-keyword">struct</span> <span class="hljs-title class_">B</span>: <span class="hljs-keyword">public</span> A &#123;<br>  <span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">foo</span><span class="hljs-params">()</span> <span class="hljs-keyword">override</span> </span>&#123;...&#125;<br>&#125;;<br><span class="hljs-keyword">struct</span> <span class="hljs-title class_">C</span>: <span class="hljs-keyword">public</span> B &#123;<br>  <span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">foo</span><span class="hljs-params">()</span> <span class="hljs-keyword">override</span> </span>&#123; A::<span class="hljs-built_in">foo</span>(); &#125;<br><span class="hljs-comment">//                     ^^^^^^^^</span><br>&#125;;<br><br><span class="hljs-comment">// 检查对pthread_*或posix_*函数调用是否判断负返回值</span><br><span class="hljs-number">21.</span> bugprone-posix-<span class="hljs-keyword">return</span><br><span class="hljs-comment">// before</span><br><span class="hljs-keyword">if</span> (<span class="hljs-built_in">posix_fadvise</span>(...) &lt; <span class="hljs-number">0</span>) &#123;&#125;<br><span class="hljs-comment">// after</span><br><span class="hljs-keyword">if</span> (<span class="hljs-built_in">posix_fadvise</span>(...) &gt; <span class="hljs-number">0</span>) &#123;&#125;<br><br><span class="hljs-comment">// 检查逻辑if的重复判断冗余</span><br><span class="hljs-number">22.</span> bugprone-redundant-branch-condition<br><span class="hljs-keyword">if</span> (onFire) &#123;<br>  <span class="hljs-keyword">if</span> (onFire &amp;&amp; peopleInTheBuilding &gt; <span class="hljs-number">0</span>)<br>    <span class="hljs-built_in">scream</span>();<br>&#125;<br><br><span class="hljs-comment">// 检查不规范的下划线使用</span><br><span class="hljs-number">23.</span> bugprone-reserved-identifier<br><br><span class="hljs-comment">// 检查容易出错的信号处理程序</span><br><span class="hljs-number">24.</span> bugprone-signal-handler<br><br><span class="hljs-comment">// 检查错误的字符型与字符型、整型之间的强制转换和比较</span><br><span class="hljs-number">25.</span> bugprone-<span class="hljs-type">signed</span>-<span class="hljs-type">char</span>-misuse<br><br><span class="hljs-comment">// 检查可能出错的sizeof使用</span><br><span class="hljs-number">26.</span> bugprone-<span class="hljs-keyword">sizeof</span>-container<br><span class="hljs-number">27.</span> bugprone-<span class="hljs-keyword">sizeof</span>-expression<br>std::string s;<br><span class="hljs-type">int</span> a = <span class="hljs-number">47</span> + <span class="hljs-built_in">sizeof</span>(s); <span class="hljs-comment">// 报错</span><br><span class="hljs-type">int</span> b = <span class="hljs-built_in">sizeof</span>(std::string); <span class="hljs-comment">// 允许</span><br><br>std::string array_of_strings[<span class="hljs-number">10</span>];<br><span class="hljs-type">int</span> c = <span class="hljs-built_in">sizeof</span>(array_of_strings) / <span class="hljs-built_in">sizeof</span>(array_of_strings[<span class="hljs-number">0</span>]); <span class="hljs-comment">// 允许</span><br><br>std::array&lt;<span class="hljs-type">int</span>, 3&gt; std_array;<br><span class="hljs-type">int</span> d = <span class="hljs-built_in">sizeof</span>(std_array); <span class="hljs-comment">// 允许</span><br><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">Point</span> &#123;<br>  [...]<br>  <span class="hljs-function"><span class="hljs-type">size_t</span> <span class="hljs-title">size</span><span class="hljs-params">()</span> </span>&#123; <span class="hljs-keyword">return</span> <span class="hljs-built_in">sizeof</span>(<span class="hljs-keyword">this</span>); &#125;  <span class="hljs-comment">// 不允许，可能是sizeof(*this)</span><br>  [...]<br>&#125;;<br><br><span class="hljs-comment">// 检查唤醒函数的错误使用</span><br><span class="hljs-number">28.</span> bugprone-spuriously-wake-up-functions<br><br><span class="hljs-comment">// 检查容易出错的字符串初始化</span><br><span class="hljs-number">29.</span> bugprone-string-<span class="hljs-function">constructor</span><br><span class="hljs-function">std::string <span class="hljs-title">str</span><span class="hljs-params">(<span class="hljs-string">&#x27;x&#x27;</span>, <span class="hljs-number">50</span>)</span></span>; <span class="hljs-comment">// should be str(50, &#x27;x&#x27;)</span><br><br><span class="hljs-comment">// 检查容易出错的字符串赋值(可能导致误判)</span><br><span class="hljs-number">30.</span> bugprone-string-integer-assignment<br>std::string s;<br><span class="hljs-type">int</span> x = <span class="hljs-number">5965</span>;<br>s = <span class="hljs-number">6</span>;	<br>s = x;<br><br><span class="hljs-comment">// 检查带有嵌入\0字符的字符串</span><br><span class="hljs-number">31.</span> bugprone-string-literal-with-embedded-nul<br><span class="hljs-type">const</span> <span class="hljs-type">char</span> *Bytes[] = <span class="hljs-string">&quot;\x03\0x02\0x01\0x00\0xFF\0xFF\0xFF&quot;</span>;<br><span class="hljs-function">std::string <span class="hljs-title">str</span><span class="hljs-params">(<span class="hljs-string">&quot;abc\0def&quot;</span>)</span></span>; <br><br><span class="hljs-comment">// 容易出错的枚举用法</span><br><span class="hljs-number">32.</span> bugprone-suspicious-<span class="hljs-keyword">enum</span>-usage<br><br><span class="hljs-comment">// 检查错误的文件包含（只包含头文件）</span><br><span class="hljs-number">33.</span> bugprone-suspicious-include.HeaderFileExtensions<br><br><span class="hljs-comment">// 检查错误的memset的使用</span><br><span class="hljs-number">34.</span> bugprone-suspicious-memset-<span class="hljs-function">usage</span><br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">foo</span><span class="hljs-params">()</span> </span>&#123;<br>  <span class="hljs-type">int</span> i[<span class="hljs-number">5</span>] = &#123;<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>&#125;;<br>  <span class="hljs-type">int</span> *ip = i;<br>  <span class="hljs-type">char</span> c = <span class="hljs-string">&#x27;1&#x27;</span>;<br>  <span class="hljs-type">char</span> *cp = &amp;c;<br>  <span class="hljs-type">int</span> v = <span class="hljs-number">0</span>;<br><br>  <span class="hljs-comment">// Case 1</span><br>  <span class="hljs-built_in">memset</span>(ip, <span class="hljs-string">&#x27;0&#x27;</span>, <span class="hljs-number">1</span>); <span class="hljs-comment">// suspicious</span><br>  <span class="hljs-built_in">memset</span>(cp, <span class="hljs-string">&#x27;0&#x27;</span>, <span class="hljs-number">1</span>); <span class="hljs-comment">// OK</span><br><br>  <span class="hljs-comment">// Case 2</span><br>  <span class="hljs-built_in">memset</span>(ip, <span class="hljs-number">0xabcd</span>, <span class="hljs-number">1</span>); <span class="hljs-comment">// fill value gets truncated</span><br>  <span class="hljs-built_in">memset</span>(ip, <span class="hljs-number">0x00</span>, <span class="hljs-number">1</span>);   <span class="hljs-comment">// OK</span><br><br>  <span class="hljs-comment">// Case 3</span><br>  <span class="hljs-built_in">memset</span>(ip, <span class="hljs-built_in">sizeof</span>(<span class="hljs-type">int</span>), v); <span class="hljs-comment">// zero length, potentially swapped</span><br>  <span class="hljs-built_in">memset</span>(ip, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>);           <span class="hljs-comment">// OK</span><br>&#125;<br><br><span class="hljs-comment">// 检查可疑的逗号丢失</span><br><span class="hljs-number">35.</span> bugprone-suspicious-missing-comma<br><span class="hljs-type">const</span> <span class="hljs-type">char</span>* B[] = <span class="hljs-string">&quot;This&quot;</span> <span class="hljs-string">&quot; is a &quot;</span>    <span class="hljs-string">&quot;test&quot;</span>; <span class="hljs-comment">// 允许</span><br><span class="hljs-type">const</span> <span class="hljs-type">char</span>* Test[] = &#123;<br>  <span class="hljs-string">&quot;line 1&quot;</span>,<br>  <span class="hljs-string">&quot;line 2&quot;</span>     <span class="hljs-comment">// 报错</span><br>  <span class="hljs-string">&quot;line 3&quot;</span>,<br>  <span class="hljs-string">&quot;line 4&quot;</span>,<br>  <span class="hljs-string">&quot;line 5&quot;</span><br>&#125;;<br><br><span class="hljs-comment">// 检查容易出错的可以分号</span><br><span class="hljs-number">36.</span> bugprone-suspicious-<span class="hljs-function">semicolon</span><br><span class="hljs-function"><span class="hljs-title">if</span> <span class="hljs-params">(x &lt; y)</span></span>;<br>&#123;<br>  x++;<br>&#125;<br><br><span class="hljs-comment">// 检查可疑的字符串比较</span><br><span class="hljs-number">37.</span> bugprone-suspicious-string-<span class="hljs-function">compare</span><br><span class="hljs-function"><span class="hljs-title">if</span> <span class="hljs-params">(strcmp(...))</span>       <span class="hljs-comment">// 建议显式比较</span></span><br><span class="hljs-function"><span class="hljs-title">if</span> <span class="hljs-params">(!strcmp(...))</span>      <span class="hljs-comment">// 允许</span></span><br><span class="hljs-function"><span class="hljs-title">if</span> <span class="hljs-params">(strcmp(...) != <span class="hljs-number">0</span>)</span>  <span class="hljs-comment">// 允许</span></span><br><span class="hljs-function"><span class="hljs-title">if</span> <span class="hljs-params">(strcmp(...) == <span class="hljs-number">-1</span>)</span> <span class="hljs-comment">// 错误</span></span><br><span class="hljs-function"><span class="hljs-title">if</span> <span class="hljs-params">(strcmp(...) &lt; <span class="hljs-number">0.</span>)</span>  <span class="hljs-comment">// 错误</span></span><br><span class="hljs-function"></span><br><span class="hljs-function"><span class="hljs-comment">// 检查容易出错的交换参数</span></span><br><span class="hljs-function">38. bugprone-swapped-arguments</span><br><span class="hljs-function"></span><br><span class="hljs-function"><span class="hljs-comment">// 检查do-while常为false时的continue使用</span></span><br><span class="hljs-function">39. bugprone-terminating-<span class="hljs-keyword">continue</span></span><br><span class="hljs-function"><span class="hljs-keyword">do</span> </span>&#123;<br>  ...<br>  <span class="hljs-keyword">continue</span>; <span class="hljs-comment">// 直接终止循环</span><br>  ...<br>&#125; <span class="hljs-keyword">while</span>(<span class="hljs-literal">false</span>);<br><br><span class="hljs-comment">// 检查可能缺失的throw关键字</span><br><span class="hljs-number">40.</span> bugprone-<span class="hljs-keyword">throw</span>-keyword-missing<br><span class="hljs-type">void</span> <span class="hljs-built_in">f</span>(<span class="hljs-type">int</span> i) &#123;<br>  <span class="hljs-keyword">if</span> (i &lt; <span class="hljs-number">0</span>) &#123;<br>    <span class="hljs-comment">// Exception is created but is not thrown.</span><br>    std::<span class="hljs-built_in">runtime_error</span>(<span class="hljs-string">&quot;Unexpected argument&quot;</span>);<br>  &#125;<br>&#125;<br><br><span class="hljs-comment">// 检查容易出错的循环变量</span><br><span class="hljs-number">41.</span> bugprone-too-small-loop-<span class="hljs-function">variable</span><br><span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>&#123;<br>  <span class="hljs-type">long</span> size = <span class="hljs-number">294967296l</span>;<br>  <span class="hljs-keyword">for</span> (<span class="hljs-type">short</span> i = <span class="hljs-number">0</span>; i &lt; size; ++i) &#123;&#125;<br>&#125;<br><span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">doSomething</span><span class="hljs-params">(<span class="hljs-type">const</span> std::vector&amp; items)</span> </span>&#123;<br>  <span class="hljs-keyword">for</span> (<span class="hljs-type">short</span> i = <span class="hljs-number">0</span>; i &lt; items.<span class="hljs-built_in">size</span>(); ++i) &#123;&#125;<br>&#125;<br><br><span class="hljs-comment">// 查找容易出错的未定义内存操作</span><br><span class="hljs-number">42.</span> bugprone-undefined-memory-manipulation<br><br><span class="hljs-comment">// 检查容易出错的委托构造函数</span><br><span class="hljs-number">43.</span> bugprone-undelegated-constructor<br><br><span class="hljs-comment">// 检查未对new进行异常处理</span><br><span class="hljs-number">44.</span> bugprone-unhandled-exception-at-<span class="hljs-keyword">new</span><br><span class="hljs-type">int</span> *<span class="hljs-built_in">f</span>() <span class="hljs-keyword">noexcept</span> &#123;<br>  <span class="hljs-type">int</span> *p = <span class="hljs-keyword">new</span> <span class="hljs-type">int</span>[<span class="hljs-number">1000</span>];<br>  <span class="hljs-comment">// ...</span><br>  <span class="hljs-comment">// std::bad_alloc</span><br>  <span class="hljs-keyword">return</span> p;<br>&#125;<br><br><span class="hljs-comment">// 检查容易出错的未处理自赋值</span><br><span class="hljs-number">55.</span> bugprone-unhandled-self-assignment<br><br><span class="hljs-comment">// 检查看起来像RAII对象的临时对象。</span><br><span class="hljs-number">56.</span> bugprone-unused-raii<br><br><span class="hljs-comment">// 检查未使用的一些返回值（如返回指针）</span><br><span class="hljs-number">57.</span> bugprone-unused-<span class="hljs-keyword">return</span>-value<br><br><span class="hljs-comment">// 禁止使用std::move之后的对象仍被使用</span><br><span class="hljs-number">58.</span> bugprone-use-after-move<br><br><span class="hljs-comment">// 检查函数名与基类虚函数类似的函数声明</span><br><span class="hljs-number">59.</span> bugprone-<span class="hljs-keyword">virtual</span>-near-miss<br><br><span class="hljs-comment">// 会报未知的警告</span><br><span class="hljs-number">60.</span> cert-dcl21-cpp<br><span class="hljs-number">61.</span> cert-dcl50-cpp<br><span class="hljs-number">62.</span> cert-env33-c<br><br><span class="hljs-comment">// 检查对std posix等命名空间的修改</span><br><span class="hljs-number">61.</span> cert-dcl58-cpp<br><br><span class="hljs-comment">// 检查不验证转换字符串到数字的有效性的代码，如c语言atoi()</span><br><span class="hljs-number">62.</span> cert-err34-c<br><br><span class="hljs-comment">// 检查浮点类型的循环</span><br><span class="hljs-number">63.</span> cert-flp30-c<br><br><span class="hljs-comment">// 生成动态类型信息</span><br><span class="hljs-number">64.</span> clang-analyzer-core.DynamicTypePropagation<br><br><span class="hljs-comment">// 检查未初始化的块</span><br><span class="hljs-number">65.</span> clang-analyzer-core.uninitialized.CapturedBlockVariable<br><br><span class="hljs-comment">// 检查释放后的内部指针的使用</span><br><span class="hljs-number">66.</span> clang-analyzer-cplusplus.InnerPointer<br><br><span class="hljs-comment">// 检查从非空返回类型 返回 可能空的指针</span><br><span class="hljs-number">67.</span> clang-analyzer-nullability.NullableReturnedFromNonnull<br><br><span class="hljs-number">68.</span> clang-analyzer-optin.osx.OSObjectCStyleCast<br><span class="hljs-number">69.</span> clang-analyzer-optin.performance.GCDAntipattern<br><span class="hljs-number">70.</span> clang-analyzer-osx.MIG<br><br><span class="hljs-comment">// 检查过度填充的结构</span><br><span class="hljs-number">71.</span> clang-analyzer-optin.performance.Padding<br><br><span class="hljs-number">72.</span> clang-analyzer-osx.OSObjectRetainCount<br><br><span class="hljs-comment">// 检查objc</span><br><span class="hljs-number">73.</span> clang-analyzer-osx.ObjCProperty <br><span class="hljs-number">74.</span> clang-analyzer-osx.cocoa.AutoreleaseWrite<br><br><span class="hljs-comment">// cocoa相关</span><br><span class="hljs-number">75.</span> -clang-analyzer-osx.cocoa-*<br><br><span class="hljs-comment">// va_lists相关</span><br><span class="hljs-number">76.</span> clang-analyzer-valist-<br><br><span class="hljs-comment">// mt安全</span><br><span class="hljs-number">77.</span> concurrency-mt-unsafe<br><br><span class="hljs-comment">// 并发线程</span><br><span class="hljs-number">78.</span> concurrency-thread-canceltype-asynchronous<br><br><span class="hljs-comment">// 避免使用goto</span><br><span class="hljs-number">79.</span> cppcoreguidelines-avoid-<span class="hljs-keyword">goto</span><br><br><span class="hljs-comment">// 禁止非常量全局变量</span><br><span class="hljs-number">80.</span> cppcoreguidelines-avoid-non-<span class="hljs-type">const</span>-global-variables<br><br><span class="hljs-comment">// 检查extern对象的全局变量的初始值设定项初始化顺序问题</span><br><span class="hljs-number">81.</span> cppcoreguidelines-interfaces-global-init<br><br><span class="hljs-comment">// 检查可能被认为有问题的宏用法</span><br><span class="hljs-number">82.</span> -cppcoreguidelines-macro-usage<br><br><span class="hljs-number">83.</span> -cppcoreguidelines-narrowing-conversions<br><br><span class="hljs-comment">// 对c风格内存分配的检查</span><br><span class="hljs-number">84.</span> cppcoreguidelines-no-malloc<br><br><span class="hljs-comment">// 检查内存分配时是否使用gsl的方法</span><br><span class="hljs-number">85.</span> -cppcoreguidelines-owning-memory<br><br><span class="hljs-number">86.</span> cppcoreguidelines-prefer-member-initializer<br><span class="hljs-number">87.</span> cppcoreguidelines-pro-bounds-array-to-pointer-decay<br><span class="hljs-number">88.</span> cppcoreguidelines-pro-bounds-constant-array-index<br><br><span class="hljs-comment">// 标记指针的算法使用</span><br><span class="hljs-number">89.</span> -cppcoreguidelines-pro-bounds-pointer-arithmetic<br><br><span class="hljs-comment">// 标记const_cast的使用</span><br><span class="hljs-number">90.</span> -cppcoreguidelines-pro-type-<span class="hljs-type">const</span>-cast<br><span class="hljs-number">91.</span> -cppcoreguidelines-pro-type-cstyle-cast<br><br><span class="hljs-number">92.</span> -cppcoreguidelines-pro-type-member-init<br><br><span class="hljs-comment">// 标记reinterpret_cast的使用</span><br><span class="hljs-number">93.</span> -cppcoreguidelines-pro-type-reinterpret-cast<br><br><span class="hljs-comment">// 标记static_cast的使用</span><br><span class="hljs-number">94.</span> -cppcoreguidelines-pro-type-<span class="hljs-type">static</span>-cast-downcast <br><br><span class="hljs-comment">// 标记union成员的访问权限</span><br><span class="hljs-number">95.</span> -cppcoreguidelines-pro-type-<span class="hljs-keyword">union</span>-access<br><br><span class="hljs-comment">// 标记对c样式可变参数函数调用以及对va_arg的使用</span><br><span class="hljs-number">96.</span> cppcoreguidelines-pro-type-vararg<br><br><span class="hljs-comment">// 检查导致slice的情况</span><br><span class="hljs-number">97.</span> cppcoreguidelines-slicing<br><span class="hljs-keyword">struct</span> B &#123; <span class="hljs-type">int</span> a; <span class="hljs-function"><span class="hljs-keyword">virtual</span> <span class="hljs-type">int</span> <span class="hljs-title">f</span><span class="hljs-params">()</span></span>; &#125;;<br><span class="hljs-keyword">struct</span> <span class="hljs-title class_">D</span> : B &#123; <span class="hljs-type">int</span> b; <span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">f</span><span class="hljs-params">()</span> <span class="hljs-keyword">override</span></span>; &#125;;<br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">use</span><span class="hljs-params">(B b)</span> </span>&#123;  <span class="hljs-comment">// Missing reference, intended?</span><br>  b.<span class="hljs-built_in">f</span>();  <span class="hljs-comment">// Calls B::f.</span><br>&#125;<br><br>D d;<br><span class="hljs-built_in">use</span>(d);  <span class="hljs-comment">// Slice</span><br><br><span class="hljs-number">98.</span> cppcoreguidelines-special-member-functions<br><span class="hljs-number">99.</span> darwin-avoid-spinlock<br><span class="hljs-number">100.</span> darwin-dispatch-once-nonstatic<br><br><span class="hljs-comment">// 使用默认参数时发出警告</span><br><span class="hljs-number">101.</span> -fuchsia-<span class="hljs-keyword">default</span>-arguments-calls<br><br><span class="hljs-comment">// 函数定义默认参数时发出警告</span><br><span class="hljs-number">102.</span> -fuchsia-<span class="hljs-keyword">default</span>-arguments-declarations<br><br><span class="hljs-comment">// 继承自多个非纯虚类发出警告</span><br><span class="hljs-number">103.</span> -fuchsia-multiple-inheritance<br><br><span class="hljs-comment">// 检查已被重载的运算符</span><br><span class="hljs-number">104.</span> -fuchsia-overloaded-<span class="hljs-keyword">operator</span><br><br><span class="hljs-comment">// 限制创建静态对象（除非构造函数是constexpr类型或没有显式构造函数）</span><br><span class="hljs-number">105.</span> fuchsia-statically-constructed-objects<br><br><span class="hljs-number">106.</span> fuchsia-trailing-<span class="hljs-keyword">return</span><br><br><span class="hljs-comment">// 对虚继承类发出警告(报错)</span><br><span class="hljs-number">107.</span> fuchsia-<span class="hljs-keyword">virtual</span>-inheritance<br><span class="hljs-keyword">class</span> B : <span class="hljs-keyword">public</span> <span class="hljs-keyword">virtual</span> A &#123;&#125;;<br><br><span class="hljs-comment">// 检查make_pair是否推断出模板类型</span><br><span class="hljs-number">108.</span> google-build-<span class="hljs-keyword">explicit</span>-make-pair<br><br><span class="hljs-comment">// 在标头中查找匿名命名空间</span><br><span class="hljs-number">109.</span>google-build-namespaces<br>- key:google-build-namespaces.HeaderFileExtensions<br>    value:h,hh,hpp,hxx<br><br><span class="hljs-comment">// 检查是否使用using namespace</span><br><span class="hljs-number">110.</span> google-build-<span class="hljs-keyword">using</span>-<span class="hljs-keyword">namespace</span><br><br><span class="hljs-comment">// 为虚函数参数添加默认值</span><br><span class="hljs-number">111.</span> google-<span class="hljs-keyword">default</span>-arguments<br><br><span class="hljs-comment">// 检查显式构造函数，避免隐式转换带来的风险</span><br><span class="hljs-number">112.</span> -google-<span class="hljs-keyword">explicit</span>-constructor<br><br><span class="hljs-comment">// 在头文件中标记全局命名空间污染</span><br><span class="hljs-number">113.</span> google-global-names-in-headers<br>  - key: google-global-names-in-headers.HeaderFileExtensions<br>    value: h<br><br><span class="hljs-comment">// objc</span><br><span class="hljs-number">114.</span> -google-objc-avoid-nsobject-<span class="hljs-keyword">new</span><br><span class="hljs-number">115.</span> -google-objc-avoid-throwing-exception<br><span class="hljs-number">116.</span> -google-objc-function-naming<br><span class="hljs-number">117.</span> -google-objc-global-variable-declaration<br><br><span class="hljs-comment">// 检查googletest的测试以及测试示例名称是否有下划线（测试名称和测试用例名称中不允许使用下划线）</span><br><span class="hljs-number">118.</span> google-readability-avoid-underscore-in-googletest-name<br><br><span class="hljs-comment">// 查找 C 风格强制转换的用法</span><br><span class="hljs-number">119.</span> google-readability-casting<br><br><span class="hljs-comment">// 查找TODO有没有署用户名、邮件等</span><br><span class="hljs-number">120.</span> google-readability-todo<br><span class="hljs-comment">// TODO(kl@gmail.com): Use a &quot;*&quot; here for concatenation operator.</span><br><span class="hljs-comment">// TODO(Zeke) change this to use relations.</span><br><span class="hljs-comment">// TODO(bug 12345): remove the &quot;Last visitors&quot; feature.</span><br><br><span class="hljs-comment">// 检查整数定义，将short, long，long long改为intxx_类型</span><br><span class="hljs-number">121.</span> -google-runtime-<span class="hljs-type">int</span><br><br><span class="hljs-comment">// 检查用户自定义表述的重载运算符</span><br><span class="hljs-number">121.</span> google-runtime-<span class="hljs-keyword">operator</span><br><br><span class="hljs-comment">// 用户自定义函数名中，将带有case字符改为suite</span><br><span class="hljs-number">122.</span> google-upgrade-googletest-<span class="hljs-keyword">case</span><br><br><span class="hljs-comment">// 要求goto只跳过块的一部分（不使用goto）</span><br><span class="hljs-number">123.</span> -hicpp-avoid-<span class="hljs-keyword">goto</span><br><br><span class="hljs-comment">// 确保throw表达式中的每个值都是std::exception的实例</span><br><span class="hljs-number">124.</span> hicpp-exception-baseclass<br><br><span class="hljs-comment">// 有if和else if一定要包含else（即使内容为空），有switch要包含default，少量case用if代替。</span><br><span class="hljs-number">125.</span> hicpp-multiway-paths-covered<br><br><span class="hljs-comment">// 检查汇编语句</span><br><span class="hljs-number">126.</span> hicpp-no-assembler<br><br><span class="hljs-comment">// 检查对有符号整数类型的按位运算的使用，避免风险</span><br><span class="hljs-number">127.</span> hicpp-<span class="hljs-type">signed</span>-bitwise<br><br><span class="hljs-comment">// 检查linux内核代码</span><br><span class="hljs-number">128.</span> linuxkernel-must-use-errs<br><br><span class="hljs-comment">// 检查不符合LLVM风格的头文件</span><br><span class="hljs-number">129.</span> llvm-header-guard<br>  - key: llvm-header-guard.HeaderFileExtensions<br>    value: <span class="hljs-string">&#x27;,h,hh,hpp,hxx&#x27;</span><br><br><span class="hljs-comment">// 检查include的正确顺序（llvm风格）</span><br><span class="hljs-number">130.</span> llvm-include-order<br><br><span class="hljs-comment">// 长命名空间结束注释</span><br><span class="hljs-number">131.</span> llvm-<span class="hljs-keyword">namespace</span>-comment<br><br><span class="hljs-comment">// cast的一些变换</span><br><span class="hljs-number">132.</span> llvm-prefer-isa-<span class="hljs-keyword">or</span>-dyn-cast-in-conditionals<br><span class="hljs-comment">// before</span><br><span class="hljs-keyword">if</span> (<span class="hljs-keyword">auto</span> x = <span class="hljs-built_in">cast</span>&lt;X&gt;(y)) &#123;&#125;<br><span class="hljs-comment">// after</span><br><span class="hljs-keyword">if</span> (<span class="hljs-keyword">auto</span> x = <span class="hljs-built_in">dyn_cast</span>&lt;X&gt;(y)) &#123;&#125;<br><span class="hljs-comment">// befo</span><br><span class="hljs-keyword">if</span> (<span class="hljs-built_in">cast</span>&lt;X&gt;(y)) &#123;&#125;<br><span class="hljs-comment">// after</span><br><span class="hljs-keyword">if</span> (<span class="hljs-built_in">isa</span>&lt;X&gt;(y)) &#123;&#125;<br><br><span class="hljs-comment">// unsigned用Register代替</span><br><span class="hljs-number">133.</span> llvm-prefer-<span class="hljs-keyword">register</span>-over-<span class="hljs-type">unsigned</span><br><br><span class="hljs-comment">// Twine方法使用后面加.str()</span><br><span class="hljs-number">134.</span> llvm-twine-local<br><span class="hljs-comment">// before</span><br><span class="hljs-type">static</span> Twine Moo = <span class="hljs-built_in">Twine</span>(<span class="hljs-string">&quot;bark&quot;</span>) + <span class="hljs-string">&quot;bah&quot;</span>;<br><span class="hljs-comment">// after</span><br><span class="hljs-type">static</span> std::string Moo = (<span class="hljs-built_in">Twine</span>(<span class="hljs-string">&quot;bark&quot;</span>) + <span class="hljs-string">&quot;bah&quot;</span>).<span class="hljs-built_in">str</span>();<br><br><span class="hljs-comment">// 检查调用解析为__llvm_libc命名空间内的函数</span><br><span class="hljs-number">135.</span> llvmlibc-callee-<span class="hljs-keyword">namespace</span><br><br><span class="hljs-number">136.</span> llvmlibc-implementation-in-<span class="hljs-keyword">namespace</span><br><br><span class="hljs-comment">// 查找编译器未提供的系统 libc 头文件,如stdio.h</span><br><span class="hljs-number">137.</span> llvmlibc-restrict-system-libc-headers<br><br><span class="hljs-comment">// 在头文件中查找非 extern 非内联函数和变量定义</span><br><span class="hljs-number">138.</span> -misc-definitions-in-headers<br><span class="hljs-type">int</span> a = <span class="hljs-number">1</span>; <span class="hljs-comment">//全局，不允许</span><br><span class="hljs-function"><span class="hljs-keyword">inline</span> <span class="hljs-type">int</span> <span class="hljs-title">e</span><span class="hljs-params">()</span> </span>&#123; <span class="hljs-comment">//允许</span><br>  <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>;<br>&#125;<br><br><span class="hljs-comment">// 检查const的错误使用</span><br><span class="hljs-number">139.</span> misc-misplaced-<span class="hljs-type">const</span><br><span class="hljs-keyword">typedef</span> <span class="hljs-type">int</span> *int_ptr;<br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">f</span><span class="hljs-params">(<span class="hljs-type">const</span> int_ptr ptr)</span> </span>&#123;<br>  *ptr = <span class="hljs-number">0</span>; <span class="hljs-comment">// 意外的修改了数值</span><br>  ptr = <span class="hljs-number">0</span>; <span class="hljs-comment">// 编译不通过</span><br>&#125;<br><br><span class="hljs-comment">// 检查new和delete</span><br><span class="hljs-number">140.</span> misc-<span class="hljs-keyword">new</span>-<span class="hljs-keyword">delete</span>-overloads<br><br><span class="hljs-comment">// 检查函数递归错误</span><br><span class="hljs-number">141.</span> misc-no-recursion<br><br><span class="hljs-comment">// 检查一些对象，不允许复制，比如FILE</span><br><span class="hljs-number">142.</span> misc-non-copyable-objects<br><br><span class="hljs-comment">// 规定类成员变量必须为private</span><br><span class="hljs-number">143.</span> -misc-non-<span class="hljs-keyword">private</span>-member-variables-in-classes <br><br><span class="hljs-comment">// 检查冗余表达式</span><br><span class="hljs-number">144.</span> misc-redundant-<span class="hljs-built_in">expression</span><br>(p-&gt;x == p-&gt;x);<br>(p-&gt;x &lt; p-&gt;x);<br><br><span class="hljs-comment">// 用static_assert()代替assert()</span><br><span class="hljs-number">145.</span> misc-<span class="hljs-type">static</span>-assert<br><br><span class="hljs-comment">// 查找违反“按值抛出，按引用捕捉”的规则</span><br><span class="hljs-number">146.</span> misc-<span class="hljs-keyword">throw</span>-by-value-<span class="hljs-keyword">catch</span>-by-reference<br><br><span class="hljs-comment">// 检查重载运算符的错误返回类型</span><br><span class="hljs-number">147.</span> misc-unconventional-assign-<span class="hljs-keyword">operator</span><br><br><span class="hljs-comment">// 将unique_ptr::reset(release())替换为std::move()</span><br><span class="hljs-number">148.</span> misc-uniqueptr-reset-release<br><br><span class="hljs-comment">// 查找未使用的命名空间别名声明</span><br><span class="hljs-number">149.</span> misc-unused-alias-decls<br><br><span class="hljs-comment">// 查找未使用的参数并报错（可能代码有误）</span><br><span class="hljs-number">150.</span> misc-unused-parameters<br><br><span class="hljs-comment">// 查找未使用的using声明</span><br><span class="hljs-number">151.</span> misc-unused-<span class="hljs-keyword">using</span>-decls<br><br><span class="hljs-comment">// 替换std::bind()的使用</span><br><span class="hljs-number">152.</span> modernize-avoid-bind<br><br><span class="hljs-comment">// 避免使用c语言的array</span><br><span class="hljs-number">153.</span> modernize-avoid-c-arrays<br><span class="hljs-type">int</span> a[] = &#123;<span class="hljs-number">1</span>, <span class="hljs-number">2</span>&#125;;<span class="hljs-comment">//报错</span><br><br><span class="hljs-comment">// 嵌套命名空间的简化（可以简化时）</span><br><span class="hljs-number">154.</span> modernize-concat-nested-namespaces<br><span class="hljs-comment">// before</span><br><span class="hljs-keyword">namespace</span> n1 &#123;<br><span class="hljs-keyword">namespace</span> n2 &#123;<br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">t</span><span class="hljs-params">()</span></span>;<br>&#125;<br>&#125;<br><span class="hljs-comment">// after</span><br><span class="hljs-keyword">namespace</span> n1::n2 &#123;<br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">t</span><span class="hljs-params">()</span></span>;<br>&#125;<br><br><span class="hljs-comment">// 检查c++中弃用的c头文件</span><br><span class="hljs-number">155.</span> modernize-deprecated-headers<br><br><span class="hljs-comment">// 检查弃用的类方法</span><br><span class="hljs-number">156.</span> modernize-deprecated-ios-base-aliases<br>弃用								替代<br>std::ios_base::io_state			std::ios_base::iostate<br>std::ios_base::open_mode		std::ios_base::openmode<br>std::ios_base::seek_dir			std::ios_base::seekdir<br>std::ios_base::streamoff	 <br>std::ios_base::streampos	 <br><br><span class="hljs-comment">// 避免有风险的循环，替换为c++11风格</span><br><span class="hljs-number">157.</span> modernize-loop-convert<br><br><span class="hljs-comment">// 对于share_ptr的一些更改</span><br><span class="hljs-number">158.</span> modernize-make-shared<br><span class="hljs-comment">// before</span><br><span class="hljs-keyword">auto</span> my_ptr = std::<span class="hljs-built_in">shared_ptr</span>&lt;MyPair&gt;(<span class="hljs-keyword">new</span> <span class="hljs-built_in">MyPair</span>(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>));<br>my_ptr.<span class="hljs-built_in">reset</span>(<span class="hljs-keyword">new</span> <span class="hljs-built_in">MyPair</span>(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>));<br><span class="hljs-comment">// after</span><br><span class="hljs-keyword">auto</span> my_ptr = std::<span class="hljs-built_in">make_shared</span>&lt;MyPair&gt;(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>);<br>my_ptr = std::<span class="hljs-built_in">make_shared</span>&lt;MyPair&gt;(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>);<br><br><span class="hljs-comment">// 对于unique_ptr的一些更改</span><br><span class="hljs-number">159.</span> modernize-make-unique<br><span class="hljs-comment">// before</span><br><span class="hljs-keyword">auto</span> my_ptr = std::<span class="hljs-built_in">unique_ptr</span>&lt;MyPair&gt;(<span class="hljs-keyword">new</span> <span class="hljs-built_in">MyPair</span>(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>));<br>my_ptr.<span class="hljs-built_in">reset</span>(<span class="hljs-keyword">new</span> <span class="hljs-built_in">MyPair</span>(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>));<br><span class="hljs-comment">// after</span><br><span class="hljs-keyword">auto</span> my_ptr = std::<span class="hljs-built_in">make_unique</span>&lt;MyPair&gt;(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>);<br>my_ptr = std::<span class="hljs-built_in">make_unique</span>&lt;MyPair&gt;(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>);<br><br><span class="hljs-number">160.</span> modernize-pass-by-value<br><br><span class="hljs-comment">// 字符串初始化的风格检查</span><br><span class="hljs-number">161.</span> modernize-raw-string-literal<br><br><span class="hljs-comment">// 检查冗余的void</span><br><span class="hljs-number">162.</span> modernize-redundant-<span class="hljs-type">void</span>-<span class="hljs-function">arg</span><br><span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">fun</span><span class="hljs-params">(<span class="hljs-type">void</span>)</span></span><br><span class="hljs-function"></span><br><span class="hljs-function"><span class="hljs-comment">// 用unique_ptr替换auto_ptr</span></span><br><span class="hljs-function">163. modernize-replace-<span class="hljs-keyword">auto</span>-ptr</span><br><span class="hljs-function"></span><br><span class="hljs-function">164. modernize-replace-disallow-copy-<span class="hljs-keyword">and</span>-assign-macro</span><br><span class="hljs-function"></span><br><span class="hljs-function"><span class="hljs-comment">// 将std::random_shuffle替换为std::shuffle</span></span><br><span class="hljs-function">165. modernize-replace-random-shuffle</span><br><span class="hljs-function"></span><br><span class="hljs-function"><span class="hljs-comment">// 用花括号初始化器列表替换返回中对构造函数的显式调用</span></span><br><span class="hljs-function">166. modernize-<span class="hljs-keyword">return</span>-braced-init-list</span><br><span class="hljs-function"><span class="hljs-comment">// before</span></span><br><span class="hljs-function">Foo <span class="hljs-title">bar</span><span class="hljs-params">()</span> </span>&#123;<br>  Baz baz;<br>  <span class="hljs-keyword">return</span> <span class="hljs-built_in">Foo</span>(baz);<br>&#125;<br><span class="hljs-comment">// after</span><br><span class="hljs-function">Foo <span class="hljs-title">bar</span><span class="hljs-params">()</span> </span>&#123;<br>  Baz baz;<br>  <span class="hljs-keyword">return</span> &#123;baz&#125;;<br>&#125;<br><br><span class="hljs-comment">// 关于缩放的使用</span><br><span class="hljs-number">167.</span> modernize-shrink-to-fit<br><br><span class="hljs-comment">// 关于static_assert空字符串的检查</span><br><span class="hljs-number">168.</span> modernize-unary-<span class="hljs-type">static</span>-assert<br><br><span class="hljs-comment">// 检查auto的使用风格</span><br><span class="hljs-number">169.</span> modernize-use-<span class="hljs-keyword">auto</span><br><br><span class="hljs-comment">// 检查bool类型，用true和false表示</span><br><span class="hljs-number">170.</span> modernize-use-<span class="hljs-type">bool</span>-literals<br><br><span class="hljs-comment">// 构造函数初始化的设定值风格</span><br><span class="hljs-number">171.</span> modernize-use-<span class="hljs-keyword">default</span>-member-init<br><span class="hljs-comment">// before</span><br><span class="hljs-built_in">A</span>() : <span class="hljs-built_in">i</span>(<span class="hljs-number">5</span>), <span class="hljs-built_in">j</span>(<span class="hljs-number">10.0</span>)<br><span class="hljs-type">int</span> i;<br><span class="hljs-type">double</span> j;<br><span class="hljs-comment">// after</span><br><span class="hljs-built_in">A</span>() &#123;&#125;<br><span class="hljs-type">int</span> i&#123;<span class="hljs-number">5</span>&#125;;<br><span class="hljs-type">double</span> j&#123;<span class="hljs-number">10.0</span>&#125;;<br><br><span class="hljs-comment">// 在std::vector、std::deque、std::list中插入的使用限制</span><br><span class="hljs-number">172.</span> -modernize-use-emplace<br><br><span class="hljs-comment">// 将特殊成员函数的默认主体替换为显式默认函数声明</span><br><span class="hljs-number">173.</span> modernize-use-equals-<span class="hljs-keyword">default</span><br><span class="hljs-comment">// before</span><br><span class="hljs-built_in">A</span>() &#123;&#125;<br><span class="hljs-comment">// after</span><br><span class="hljs-built_in">A</span>() = <span class="hljs-keyword">default</span>;<br><br><span class="hljs-comment">// 将删除的特殊成员函数显式表示</span><br><span class="hljs-number">174.</span> modernize-use-equals-<span class="hljs-function"><span class="hljs-keyword">delete</span></span><br><span class="hljs-function"><span class="hljs-title">A</span><span class="hljs-params">(<span class="hljs-type">const</span> A&amp;)</span> </span>= <span class="hljs-keyword">delete</span>;	<br><br><span class="hljs-comment">// const成员函数的使用风格</span><br><span class="hljs-number">175.</span> -modernize-use-nodiscard<br><br><span class="hljs-comment">// 函数定义的throw替换为noexcept</span><br><span class="hljs-number">176.</span> modernize-use-<span class="hljs-keyword">noexcept</span><br><span class="hljs-comment">// before</span><br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">foo</span><span class="hljs-params">()</span> <span class="hljs-title">throw</span><span class="hljs-params">()</span></span>;<br><span class="hljs-comment">// after</span><br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">foo</span><span class="hljs-params">()</span> <span class="hljs-keyword">noexcept</span></span>;<br><br><span class="hljs-comment">// 将空指针NULL改为nullptr</span><br><span class="hljs-number">177.</span> -modernize-use-<span class="hljs-literal">nullptr</span><br><br><span class="hljs-comment">// 在重载虚函数中添加override声明</span><br><span class="hljs-number">178.</span> modernize-use-<span class="hljs-keyword">override</span><br><br><span class="hljs-comment">// 使用尾随返回类型</span><br><span class="hljs-number">179.</span> -modernize-use-trailing-<span class="hljs-keyword">return</span>-type<br><br><span class="hljs-number">180.</span> modernize-use-transparent-functors<br><span class="hljs-number">181.</span> modernize-use-uncaught-exceptions<br><br><span class="hljs-comment">// 将typedef转换为using</span><br><span class="hljs-number">182.</span> modernize-use-<span class="hljs-keyword">using</span><br><span class="hljs-comment">// before</span><br><span class="hljs-keyword">typedef</span> <span class="hljs-type">int</span> variable;<br><span class="hljs-comment">// after</span><br><span class="hljs-keyword">using</span> variable = <span class="hljs-type">int</span>;<br><br><span class="hljs-comment">// 关于消息传递接口的检查</span><br><span class="hljs-number">183.</span> mpi-buffer-deref<br><br><span class="hljs-comment">// 检查消息传递接口不匹配问题</span><br><span class="hljs-number">184.</span> mpi-type-mismatch<br><br><span class="hljs-comment">// objc相关</span><br><span class="hljs-number">185.</span> objc-avoid-nserror-init	 <br><span class="hljs-number">186.</span> objc-dealloc-in-category	 <br><span class="hljs-number">187.</span> objc-forbidden-subclassing	 <br><span class="hljs-number">188.</span> objc-missing-hash	 <br><span class="hljs-number">189.</span> objc-nsinvocation-argument-lifetime<br><span class="hljs-number">190.</span> objc-property-declaration<br><span class="hljs-number">191.</span> objc-super-self<br><br><span class="hljs-comment">// openmp相关</span><br><span class="hljs-number">192.</span> openmp-exception-escape	 <br><span class="hljs-number">193.</span> openmp-use-<span class="hljs-keyword">default</span>-none<br><br><span class="hljs-comment">// 优化find的效率</span><br><span class="hljs-number">194.</span> performance-faster-string-find<br><span class="hljs-comment">// before</span><br>str.<span class="hljs-built_in">find</span>(<span class="hljs-string">&quot;A&quot;</span>);<br><span class="hljs-comment">// after</span><br>str.<span class="hljs-built_in">find</span>(<span class="hljs-string">&#x27;A&#x27;</span>);<br><br><span class="hljs-comment">// 不使用for循环里使用auto的警告</span><br><span class="hljs-number">195.</span> performance-<span class="hljs-keyword">for</span>-range-copy<br>  - key:             performance-<span class="hljs-keyword">for</span>-range-copy.WarnOnAllAutoCopies<br>    value:           <span class="hljs-string">&#x27;0&#x27;</span><br><br><span class="hljs-comment">// for循环中，变量的隐式表示（auto）代替显式表示</span><br><span class="hljs-number">196.</span> performance-implicit-conversion-in-loop<br><br><span class="hljs-comment">// 检查关联容器中的低效使用</span><br><span class="hljs-number">197.</span> performance-inefficient-algorithm<br><span class="hljs-comment">// before</span><br><span class="hljs-keyword">auto</span> it = std::<span class="hljs-built_in">find</span>(s.<span class="hljs-built_in">begin</span>(), s.<span class="hljs-built_in">end</span>(), <span class="hljs-number">43</span>);<br><span class="hljs-comment">// after</span><br><span class="hljs-keyword">auto</span> it = s.<span class="hljs-built_in">find</span>(<span class="hljs-number">43</span>);<br><br><span class="hljs-comment">// 检查性能低效的字符串连接，字符串拼接改为append，而不是操作符+</span><br><span class="hljs-number">198.</span> performance-inefficient-string-concatenation<br><br><span class="hljs-comment">// 查找可能导致不必要的内存重新分配的低效vector操作</span><br><span class="hljs-number">199.</span> -performance-inefficient-vector-operation<br><br><span class="hljs-comment">// 关于std::move的一些警告</span><br><span class="hljs-number">200.</span> performance-move-<span class="hljs-type">const</span>-arg<br><br><span class="hljs-comment">// 标记移动构造函数初始化</span><br><span class="hljs-number">201.</span> performance-move-constructor-init<br><br><span class="hljs-number">202.</span> performance-no-automatic-move<br><br><span class="hljs-comment">// 限制整数到指针的转换</span><br><span class="hljs-number">203.</span> performance-no-<span class="hljs-type">int</span>-to-ptr<br><br><span class="hljs-comment">// 检查移动构造函数没有标记noexcept或者为false的情况</span><br><span class="hljs-number">204.</span> performance-<span class="hljs-keyword">noexcept</span>-move-constructor<br><br><span class="hljs-comment">// 检查外部可破坏析构函数的情况</span><br><span class="hljs-number">205.</span> performance-trivially-destructible<br><br><span class="hljs-comment">// 数学库，从c到c++的转换</span><br><span class="hljs-number">206.</span> performance-type-promotion-in-math-fn<br><br><span class="hljs-number">207.</span> performance-unnecessary-copy-initialization<br><br><span class="hljs-comment">// 使用参数的移动(std::move)，而不是复制</span><br><span class="hljs-number">208.</span> performance-unnecessary-value-param<br><br><span class="hljs-comment">// 检查以选择性地允许或禁止系统标头的可配置列表</span><br><span class="hljs-number">209.</span> portability-restrict-system-includes<br><br><span class="hljs-number">210.</span> portability-simd-intrinsics<br><br><span class="hljs-comment">// 检查函数声明是否具有顶级参数 const</span><br><span class="hljs-number">211.</span> -readability-avoid-<span class="hljs-type">const</span>-params-in-decls<br><br><span class="hljs-comment">// 在逻辑语句是否添加大括号</span><br><span class="hljs-number">212.</span> readability-braces-around-statements<br><span class="hljs-comment">// before</span><br><span class="hljs-keyword">if</span> (condition)<br>  statement;<br><span class="hljs-comment">// after</span><br><span class="hljs-keyword">if</span> (condition) &#123;<br>  statement;<br>&#125;<br><br><span class="hljs-comment">// 常量返回值的限制</span><br><span class="hljs-number">213.</span> readability-<span class="hljs-type">const</span>-<span class="hljs-keyword">return</span>-type<br><br><span class="hljs-comment">// 检查对size()调用是否可以用empty()来代替</span><br><span class="hljs-number">214.</span> readability-container-size-empty<br><br><span class="hljs-comment">// 将不使用this的非静态成员函数转换为静态成员函数</span><br><span class="hljs-number">215.</span> readability-convert-member-functions-to-<span class="hljs-type">static</span><br><br><span class="hljs-comment">// 查找检查指针是否存在的语句</span><br><span class="hljs-number">216.</span> -readability-<span class="hljs-keyword">delete</span>-null-pointer<br><br><span class="hljs-comment">// 检查多余的else使用</span><br><span class="hljs-number">217.</span> readability-<span class="hljs-keyword">else</span>-after-<span class="hljs-keyword">return</span><br><span class="hljs-comment">// before</span><br><span class="hljs-keyword">if</span> (Value == <span class="hljs-number">1</span>) &#123;<br>  <span class="hljs-keyword">return</span>;<br>&#125; <span class="hljs-keyword">else</span> &#123;<br>  Local++;<br>&#125;<br><span class="hljs-comment">// after</span><br><span class="hljs-keyword">if</span> (Value == <span class="hljs-number">1</span>) &#123;<br>  <span class="hljs-keyword">return</span>;<br>&#125;<br>Local++;<br><br><span class="hljs-comment">// 检查功能认知复杂性指标</span><br><span class="hljs-number">218.</span> readability-function-cognitive-complexity<br><br><span class="hljs-comment">// 根据各种指标检查大型函数</span><br><span class="hljs-number">219.</span> readability-function-size<br><span class="hljs-comment">// 限制函数的控制语句数</span><br>- key:             readability-function-size.BranchThreshold<br>value:           <span class="hljs-string">&#x27;-1&#x27;</span><br><span class="hljs-comment">// 限制函数的行数</span><br>- key:             readability-function-size.LineThreshold<br>value:           <span class="hljs-string">&#x27;-1&#x27;</span><br><span class="hljs-comment">// 限制函数的参数数量</span><br>- key:             readability-function-size.ParameterThreshold<br>value:           <span class="hljs-string">&#x27;-1&#x27;</span><br><span class="hljs-comment">// 限制函数的语句数</span><br>- key:             readability-function-size.StatementThreshold<br>value:           <span class="hljs-string">&#x27;800&#x27;</span><br><br><span class="hljs-comment">// 标识符命名方式限制</span><br><span class="hljs-number">220.</span> readability-identifier-naming<br><br><span class="hljs-comment">// 检查bool与int之间的转换</span><br><span class="hljs-number">221.</span> readability-implicit-<span class="hljs-type">bool</span>-conversion<br><br><span class="hljs-comment">// 查找参数名称不一致的声明</span><br><span class="hljs-number">222.</span> readability-inconsistent-declaration-parameter-name<br><span class="hljs-comment">// in foo.hpp:</span><br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">foo</span><span class="hljs-params">(<span class="hljs-type">int</span> a, <span class="hljs-type">int</span> b, <span class="hljs-type">int</span> c)</span></span>;<br><span class="hljs-comment">// in foo.cpp:</span><br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">foo</span><span class="hljs-params">(<span class="hljs-type">int</span> d, <span class="hljs-type">int</span> e, <span class="hljs-type">int</span> f)</span></span>; <br><br><span class="hljs-comment">// 将连续的变量声明拆分成逐一声明</span><br><span class="hljs-number">223.</span> readability-isolate-declaration<br><span class="hljs-comment">// before</span><br><span class="hljs-type">int</span> * pointer = <span class="hljs-literal">nullptr</span>, value = <span class="hljs-number">42</span>, * <span class="hljs-type">const</span> const_ptr = &amp;value;<br><span class="hljs-comment">// after</span><br><span class="hljs-type">int</span> * pointer = <span class="hljs-literal">nullptr</span>;<br><span class="hljs-type">int</span> value = <span class="hljs-number">42</span>;<br><span class="hljs-type">int</span> * <span class="hljs-type">const</span> const_ptr = &amp;value;<br><br><span class="hljs-comment">// magic numbers检查</span><br><span class="hljs-number">224.</span> readability-magic-numbers<br><br><span class="hljs-comment">// 检查可以被定义为const的非静态成员函数</span><br><span class="hljs-number">225.</span> readability-make-member-function-<span class="hljs-type">const</span><br><br><span class="hljs-comment">// 检查误导性缩进</span><br><span class="hljs-number">226.</span> readability-misleading-indentation<br><span class="hljs-comment">// Dangling else:</span><br><span class="hljs-keyword">if</span> (cond1)<br>  <span class="hljs-keyword">if</span> (cond2)<br>    <span class="hljs-built_in">foo1</span>();<br><span class="hljs-keyword">else</span><br>  <span class="hljs-built_in">foo2</span>();<br><br><span class="hljs-comment">// 检查出错的索引</span><br><span class="hljs-number">227.</span> readability-misplaced-array-<span class="hljs-function">index</span><br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">f</span><span class="hljs-params">(<span class="hljs-type">int</span> *X, <span class="hljs-type">int</span> Y)</span> </span>&#123;<br>  Y[X] = <span class="hljs-number">0</span>;<br>&#125;<br><br><span class="hljs-comment">// 查找带有未命名参数的函数</span><br><span class="hljs-number">228.</span> readability-named-parameter<br><br><span class="hljs-comment">// 检查可以更改为指向常量类型的指针类型的函数参数</span><br><span class="hljs-number">229.</span> readability-non-<span class="hljs-type">const</span>-parameter<br><br><span class="hljs-comment">// 将指针限定添加到auto推导为指针的类型变量</span><br><span class="hljs-number">230.</span> readability-qualified-<span class="hljs-keyword">auto</span><br><span class="hljs-comment">// before</span><br><span class="hljs-keyword">for</span> (<span class="hljs-keyword">auto</span> Data : MutatablePtrContainer) &#123;<br>  <span class="hljs-built_in">change</span>(*Data);<br>&#125;<br><span class="hljs-keyword">for</span> (<span class="hljs-keyword">auto</span> Data : ConstantPtrContainer) &#123;<br>  <span class="hljs-built_in">observe</span>(*Data);<br>&#125;<br><span class="hljs-comment">// after</span><br><span class="hljs-keyword">for</span> (<span class="hljs-keyword">auto</span> *Data : MutatablePtrContainer) &#123;<br>  <span class="hljs-built_in">change</span>(*Data);<br>&#125;<br><span class="hljs-keyword">for</span> (<span class="hljs-type">const</span> <span class="hljs-keyword">auto</span> *Data : ConstantPtrContainer) &#123;<br>  <span class="hljs-built_in">observe</span>(*Data);<br>&#125;<br><br><span class="hljs-comment">// 删除冗余的访问类型说明</span><br><span class="hljs-number">231.</span> readability-redundant-access-specifiers<br><br><span class="hljs-comment">// 删除无用的return和continue</span><br><span class="hljs-number">232.</span> readability-redundant-control-flow<br><br><span class="hljs-comment">// 删除冗余的变量和函数声明</span><br><span class="hljs-number">233.</span> readability-redundant-declaration<br><br><span class="hljs-comment">// 删除多余的指针冗余</span><br><span class="hljs-number">234.</span> readability-redundant-function-ptr-dereference<br><span class="hljs-comment">// before</span><br><span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">f</span><span class="hljs-params">(<span class="hljs-type">int</span>,<span class="hljs-type">int</span>)</span></span>;<br><span class="hljs-built_in">int</span> (*p)(<span class="hljs-type">int</span>, <span class="hljs-type">int</span>) = &amp;f;<br><span class="hljs-type">int</span> i = (**p)(<span class="hljs-number">10</span>, <span class="hljs-number">50</span>);<br><span class="hljs-comment">// after</span><br><span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">f</span><span class="hljs-params">(<span class="hljs-type">int</span>,<span class="hljs-type">int</span>)</span></span>;<br><span class="hljs-built_in">int</span> (*p)(<span class="hljs-type">int</span>, <span class="hljs-type">int</span>) = &amp;f;<br><span class="hljs-type">int</span> i = (*p)(<span class="hljs-number">10</span>, <span class="hljs-number">50</span>);<br><br><span class="hljs-comment">// 查找多余的成员初始化</span><br><span class="hljs-number">235.</span> readability-redundant-member-init<br><br><span class="hljs-comment">// 查找潜在的冗余预处理器指令</span><br><span class="hljs-number">236.</span> readability-redundant-preprocessor<br><br><span class="hljs-comment">// 删除对智能指针.get()方法的冗余调用</span><br><span class="hljs-number">237.</span> readability-redundant-smartptr-get<br><br><span class="hljs-comment">// 检查不必要的调用：std::string::c_str()和std::string::data()</span><br><span class="hljs-number">238.</span> readability-redundant-string-cstr<br><br><span class="hljs-comment">// 查找不必要的字符串初始化</span><br><span class="hljs-number">239.</span> readability-redundant-string-init<br><br><span class="hljs-comment">// 简化对bool类型的使用</span><br><span class="hljs-number">240.</span> readability-simplify-boolean-expr<br><span class="hljs-comment">// before</span><br><span class="hljs-keyword">if</span> (b == <span class="hljs-literal">true</span>)	<br><span class="hljs-comment">// after</span><br><span class="hljs-keyword">if</span> (b)<br><br><span class="hljs-comment">// 简化下标表达式</span><br><span class="hljs-number">241.</span> readability-simplify-subscript-expr<br><span class="hljs-comment">// before</span><br><span class="hljs-type">char</span> c = s.<span class="hljs-built_in">data</span>()[i];  <br><span class="hljs-comment">// after</span><br><span class="hljs-type">char</span> c = s[i];<br><br><span class="hljs-comment">// 优化类静态成员的访问方式</span><br><span class="hljs-number">242.</span> readability-<span class="hljs-type">static</span>-accessed-through-instance<br><span class="hljs-comment">// before</span><br>C *c1 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">C</span>();<br>c1-&gt;<span class="hljs-built_in">foo</span>();<br>c1-&gt;x;<br><span class="hljs-comment">// after</span><br>C *c1 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">C</span>();<br>C::<span class="hljs-built_in">foo</span>();<br>C::x;<br><br><span class="hljs-comment">// 检查匿名命名空间中的静态成员定义</span><br><span class="hljs-number">243.</span> readability-<span class="hljs-type">static</span>-definition-in-anonymous-<span class="hljs-keyword">namespace</span><br><br><span class="hljs-comment">// 优化字符串比较的使用，尽量使用==或者!=</span><br><span class="hljs-number">244.</span> readability-string-<span class="hljs-function">compare</span><br><span class="hljs-function"><span class="hljs-title">if</span> <span class="hljs-params">(str1.compare(str2))</span></span><br><span class="hljs-function"><span class="hljs-title">if</span> <span class="hljs-params">(!str1.compare(str2))</span></span><br><span class="hljs-function"></span><br><span class="hljs-function"><span class="hljs-comment">// 传参缩写检查</span></span><br><span class="hljs-function">245. readability-suspicious-call-argument</span><br><span class="hljs-function"></span><br><span class="hljs-function"><span class="hljs-comment">// 替换&lt;unique_ptr&gt;.release()为&lt;unique_ptr&gt; = nullptr</span></span><br><span class="hljs-function">246. readability-uniqueptr-<span class="hljs-keyword">delete</span>-release</span><br><span class="hljs-function"><span class="hljs-comment">// before</span></span><br><span class="hljs-function">std::unique_ptr&lt;<span class="hljs-type">int</span>&gt; P</span>;<br><span class="hljs-keyword">delete</span> P.<span class="hljs-built_in">release</span>();<br><span class="hljs-comment">// after</span><br>std::unique_ptr&lt;<span class="hljs-type">int</span>&gt; P;<br>P = <span class="hljs-literal">nullptr</span>;<br><br><span class="hljs-comment">// 要求整数后缀为大写字符</span><br><span class="hljs-number">247.</span> readability-uppercase-literal-suffix<br><span class="hljs-comment">// before</span><br><span class="hljs-keyword">auto</span> x = <span class="hljs-number">1u</span>;<br><span class="hljs-comment">// after</span><br><span class="hljs-keyword">auto</span> x = <span class="hljs-number">1U</span>;<br><br><span class="hljs-number">248.</span> readability-use-anyofallof<br><span class="hljs-number">249.</span> zircon-temporary-objects<br></code></pre></td></tr></table></figure>

<h4 id="3-2-2-导出Clion-2022-1"><a href="#3-2-2-导出Clion-2022-1" class="headerlink" title="3.2.2 导出Clion 2022.1"></a>3.2.2 导出Clion 2022.1</h4><p><code>.clangd</code></p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-comment"># https://youtrack.jetbrains.com/articles/CPP-A-90276519/Clang-Tidy-in-CLion-20213-default-configuration</span><br><span class="hljs-attr">CompileFlags:</span>                             <br>    <span class="hljs-attr">Add:</span> <br>      [<br>        <span class="hljs-string">-std=c++20</span>,<br>        <span class="hljs-string">-Wno-documentation</span>,<br>        <span class="hljs-string">-Wno-missing-prototypes</span>,<br>        <span class="hljs-string">-Wno-unused-variable</span>,<br>        <span class="hljs-string">-Wno-infinite-recursion</span>,<br>        <span class="hljs-string">-Werror=implicit-function-declaration</span>,<br>        <span class="hljs-string">-Wshadow</span>,<br>        <span class="hljs-string">-Wno-shadow-field-in-constructor-modified</span>,<br>        <span class="hljs-string">-Wno-shadow-ivar</span>,<br>        <span class="hljs-string">-Wuninitialized</span>,<br>        <span class="hljs-string">-Wunused-label</span>,<br>        <span class="hljs-string">-Wunused-lambda-capture</span><br>      ]<br><span class="hljs-attr">Diagnostics:</span><br>  <span class="hljs-attr">ClangTidy:</span><br>    <span class="hljs-attr">Add:</span><br>    [<br>        <span class="hljs-string">bugprone-argument-comment</span>,<br>        <span class="hljs-string">bugprone-assert-side-effect</span>,<br>        <span class="hljs-string">bugprone-bad-signal-to-kill-thread</span>,<br>        <span class="hljs-string">bugprone-branch-clone</span>,<br>        <span class="hljs-string">bugprone-copy-constructor-init</span>,<br>        <span class="hljs-string">bugprone-dangling-handle</span>,<br>        <span class="hljs-string">bugprone-dynamic-static-initializers</span>,<br>        <span class="hljs-string">bugprone-fold-init-type</span>,<br>        <span class="hljs-string">bugprone-forward-declaration-namespace</span>,<br>        <span class="hljs-string">bugprone-forwarding-reference-overload</span>,<br>        <span class="hljs-string">bugprone-incorrect-roundings</span>,<br>        <span class="hljs-string">bugprone-inaccurate-erase</span>,<br>        <span class="hljs-string">bugprone-integer-division</span>,<br>        <span class="hljs-string">bugprone-lambda-function-name</span>,<br>        <span class="hljs-string">bugprone-macro-parentheses</span>,<br>        <span class="hljs-string">bugprone-macro-repeated-side-effects</span>,<br>        <span class="hljs-string">bugprone-misplaced-operator-in-strlen-in-alloc</span>,<br>        <span class="hljs-string">bugprone-misplaced-pointer-arithmetic-in-alloc</span>,<br>        <span class="hljs-string">bugprone-misplaced-widening-cast</span>,<br>        <span class="hljs-string">bugprone-move-forwarding-reference</span>,<br>        <span class="hljs-string">bugprone-multiple-statement-macro</span>,<br>        <span class="hljs-string">bugprone-narrowing-conversions</span>,<br>        <span class="hljs-string">bugprone-no-escape</span>,<br>        <span class="hljs-string">bugprone-not-null-terminated-result</span>,<br>        <span class="hljs-string">bugprone-parent-virtual-call</span>,<br>        <span class="hljs-string">bugprone-posix-return</span>,<br>        <span class="hljs-string">bugprone-reserved-identifier</span>,<br>        <span class="hljs-string">bugprone-sizeof-container</span>,<br>        <span class="hljs-string">bugprone-sizeof-expression</span>,<br>        <span class="hljs-string">bugprone-string-constructor</span>,<br>        <span class="hljs-string">bugprone-string-integer-assignment</span>,<br>        <span class="hljs-string">bugprone-string-literal-with-embedded-nul</span>,<br>        <span class="hljs-string">bugprone-suspicious-enum-usage</span>,<br>        <span class="hljs-string">bugprone-suspicious-include</span>,<br>        <span class="hljs-string">bugprone-suspicious-memory-comparison</span>,<br>        <span class="hljs-string">bugprone-suspicious-memset-usage</span>,<br>        <span class="hljs-string">bugprone-suspicious-missing-comma</span>,<br>        <span class="hljs-string">bugprone-suspicious-semicolon</span>,<br>        <span class="hljs-string">bugprone-suspicious-string-compare</span>,<br>        <span class="hljs-string">bugprone-swapped-arguments</span>,<br>        <span class="hljs-string">bugprone-terminating-continue</span>,<br>        <span class="hljs-string">bugprone-throw-keyword-missing</span>,<br>        <span class="hljs-string">bugprone-too-small-loop-variable</span>,<br>        <span class="hljs-string">bugprone-undefined-memory-manipulation</span>,<br>        <span class="hljs-string">bugprone-undelegated-constructor</span>,<br>        <span class="hljs-string">bugprone-unhandled-self-assignment</span>,<br>        <span class="hljs-string">bugprone-unused-raii</span>,<br>        <span class="hljs-string">bugprone-unused-return-value</span>,<br>        <span class="hljs-string">bugprone-use-after-move</span>,<br>        <span class="hljs-string">bugprone-virtual-near-miss</span>,<br>        <span class="hljs-string">boost-use-to-string</span>,<br>        <span class="hljs-string">cert-dcl03-c</span>,<br>        <span class="hljs-string">cert-dcl21-cpp</span>,<br>        <span class="hljs-string">cert-dcl58-cpp</span>,<br>        <span class="hljs-string">cert-err34-c</span>,<br>        <span class="hljs-string">cert-err52-cpp</span>,<br>        <span class="hljs-string">cert-err58-cpp</span>,<br>        <span class="hljs-string">cert-err60-cpp</span>,<br>        <span class="hljs-string">cert-flp30-c</span>,<br>        <span class="hljs-string">cert-msc50-cpp</span>,<br>        <span class="hljs-string">cert-msc51-cpp</span>,<br>        <span class="hljs-string">cert-oop54-cpp</span>,<br>        <span class="hljs-string">cert-str34-c</span>,<br>        <span class="hljs-string">cppcoreguidelines-interfaces-global-init</span>,<br>        <span class="hljs-string">cppcoreguidelines-narrowing-conversions</span>,<br>        <span class="hljs-string">cppcoreguidelines-pro-type-static-cast-downcast</span>,<br>        <span class="hljs-string">cppcoreguidelines-slicing</span>,<br>        <span class="hljs-string">google-default-arguments</span>,<br>        <span class="hljs-string">google-explicit-constructor</span>,<br>        <span class="hljs-string">google-runtime-operator</span>,<br>        <span class="hljs-string">hicpp-exception-baseclass</span>,<br>        <span class="hljs-string">hicpp-multiway-paths-covered</span>,<br>        <span class="hljs-string">hicpp-signed-bitwise</span>,<br>        <span class="hljs-string">misc-misplaced-const</span>,<br>        <span class="hljs-string">misc-new-delete-overloads</span>,<br>        <span class="hljs-string">misc-no-recursion</span>,<br>        <span class="hljs-string">misc-non-copyable-objects</span>,<br>        <span class="hljs-string">misc-redundant-expression</span>,<br>        <span class="hljs-string">misc-static-assert</span>,<br>        <span class="hljs-string">misc-throw-by-value-catch-by-reference</span>,<br>        <span class="hljs-string">misc-unconventional-assign-operator</span>,<br>        <span class="hljs-string">misc-uniqueptr-reset-release</span>,<br>        <span class="hljs-string">modernize-avoid-bind</span>,<br>        <span class="hljs-string">modernize-concat-nested-namespaces</span>,<br>        <span class="hljs-string">modernize-deprecated-headers</span>,<br>        <span class="hljs-string">modernize-deprecated-ios-base-aliases</span>,<br>        <span class="hljs-string">modernize-loop-convert</span>,<br>        <span class="hljs-string">modernize-make-shared</span>,<br>        <span class="hljs-string">modernize-make-unique</span>,<br>        <span class="hljs-string">modernize-pass-by-value</span>,<br>        <span class="hljs-string">modernize-raw-string-literal</span>,<br>        <span class="hljs-string">modernize-redundant-void-arg</span>,<br>        <span class="hljs-string">modernize-replace-auto-ptr</span>,<br>        <span class="hljs-string">modernize-replace-disallow-copy-and-assign-macro</span>,<br>        <span class="hljs-string">modernize-replace-random-shuffle</span>,<br>        <span class="hljs-string">modernize-return-braced-init-list</span>,<br>        <span class="hljs-string">modernize-shrink-to-fit</span>,<br>        <span class="hljs-string">modernize-unary-static-assert</span>,<br>        <span class="hljs-string">modernize-use-auto</span>,<br>        <span class="hljs-string">modernize-use-bool-literals</span>,<br>        <span class="hljs-string">modernize-use-emplace</span>,<br>        <span class="hljs-string">modernize-use-equals-default</span>,<br>        <span class="hljs-string">modernize-use-equals-delete</span>,<br>        <span class="hljs-string">modernize-use-nodiscard</span>,<br>        <span class="hljs-string">modernize-use-noexcept</span>,<br>        <span class="hljs-string">modernize-use-nullptr</span>,<br>        <span class="hljs-string">modernize-use-override</span>,<br>        <span class="hljs-string">modernize-use-transparent-functors</span>,<br>        <span class="hljs-string">modernize-use-uncaught-exceptions</span>,<br>        <span class="hljs-string">openmp-use-default-none</span>,<br>        <span class="hljs-string">performance-faster-string-find</span>,<br>        <span class="hljs-string">performance-for-range-copy</span>,<br>        <span class="hljs-string">performance-implicit-conversion-in-loop</span>,<br>        <span class="hljs-string">performance-inefficient-algorithm</span>,<br>        <span class="hljs-string">performance-inefficient-string-concatenation</span>,<br>        <span class="hljs-string">performance-inefficient-vector-operation</span>,<br>        <span class="hljs-string">performance-move-const-arg</span>,<br>        <span class="hljs-string">performance-move-constructor-init</span>,<br>        <span class="hljs-string">performance-no-automatic-move</span>,<br>        <span class="hljs-string">performance-noexcept-move-constructor</span>,<br>        <span class="hljs-string">performance-trivially-destructible</span>,<br>        <span class="hljs-string">performance-type-promotion-in-math-fn</span>,<br>        <span class="hljs-string">performance-unnecessary-copy-initialization</span>,<br>        <span class="hljs-string">performance-unnecessary-value-param</span>,<br>        <span class="hljs-string">portability-simd-intrinsics</span>,<br>        <span class="hljs-string">readability-avoid-const-params-in-decls</span>,<br>        <span class="hljs-string">readability-const-return-type</span>,<br>        <span class="hljs-string">readability-container-size-empty</span>,<br>        <span class="hljs-string">readability-convert-member-functions-to-static</span>,<br>        <span class="hljs-string">readability-delete-null-pointer</span>,<br>        <span class="hljs-string">readability-inconsistent-declaration-parameter-name</span>,<br>        <span class="hljs-string">readability-make-member-function-const</span>,<br>        <span class="hljs-string">readability-misleading-indentation</span>,<br>        <span class="hljs-string">readability-misplaced-array-index</span>,<br>        <span class="hljs-string">readability-non-const-parameter</span>,<br>        <span class="hljs-string">readability-redundant-control-flow</span>,<br>        <span class="hljs-string">readability-redundant-declaration</span>,<br>        <span class="hljs-string">readability-redundant-function-ptr-dereference</span>,<br>        <span class="hljs-string">readability-redundant-smartptr-get</span>,<br>        <span class="hljs-string">readability-redundant-string-cstr</span>,<br>        <span class="hljs-string">readability-redundant-string-init</span>,<br>        <span class="hljs-string">readability-simplify-subscript-expr</span>,<br>        <span class="hljs-string">readability-static-accessed-through-instance</span>,<br>        <span class="hljs-string">readability-static-definition-in-anonymous-namespace</span>,<br>        <span class="hljs-string">readability-string-compare</span>,<br>        <span class="hljs-string">readability-uniqueptr-delete-release</span>,<br>      	<span class="hljs-string">readability-use-anyofallof</span><br>    ]<br>    <span class="hljs-attr">Remove:</span><br>    [<br><br>    ]<br><br><br></code></pre></td></tr></table></figure>

<h3 id="3-3-clang-format"><a href="#3-3-clang-format" class="headerlink" title="3.3 .clang-format"></a>3.3 .clang-format</h3><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-comment"># 语言: None, Cpp, Java, JavaScript, ObjC, Proto, TableGen, TextProto</span><br><span class="hljs-attr">Language:</span> <span class="hljs-string">Cpp</span><br><span class="hljs-comment"># BasedOnStyle: LLVM</span><br><br><span class="hljs-comment"># 访问说明符(public、private等)的偏移</span><br><span class="hljs-attr">AccessModifierOffset:</span> <span class="hljs-number">-4</span><br><br><span class="hljs-comment"># 开括号(开圆括号、开尖括号、开方括号)后的对齐: Align, DontAlign, AlwaysBreak(总是在开括号后换行)</span><br><span class="hljs-attr">AlignAfterOpenBracket:</span> <span class="hljs-string">Align</span><br><br><span class="hljs-comment"># 连续赋值时，对齐所有等号</span><br><span class="hljs-attr">AlignConsecutiveAssignments:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-comment"># 连续声明时，对齐所有声明的变量名</span><br><span class="hljs-attr">AlignConsecutiveDeclarations:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-comment"># 右对齐逃脱换行(使用反斜杠换行)的反斜杠</span><br><span class="hljs-attr">AlignEscapedNewlines:</span> <span class="hljs-string">Right</span><br><br><span class="hljs-comment"># 水平对齐二元和三元表达式的操作数</span><br><span class="hljs-attr">AlignOperands:</span> <span class="hljs-literal">true</span><br><br><span class="hljs-comment"># 对齐连续的尾随的注释</span><br><span class="hljs-attr">AlignTrailingComments:</span> <span class="hljs-literal">true</span><br><br><span class="hljs-comment"># 不允许函数声明的所有参数在放在下一行</span><br><span class="hljs-attr">AllowAllParametersOfDeclarationOnNextLine:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-comment"># 不允许短的块放在同一行</span><br><span class="hljs-attr">AllowShortBlocksOnASingleLine:</span> <span class="hljs-literal">true</span><br><br><span class="hljs-comment"># 允许短的case标签放在同一行</span><br><span class="hljs-attr">AllowShortCaseLabelsOnASingleLine:</span> <span class="hljs-literal">true</span><br><br><span class="hljs-comment"># 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中，空函数), All</span><br><span class="hljs-attr">AllowShortFunctionsOnASingleLine:</span> <span class="hljs-string">None</span><br><br><span class="hljs-comment"># 允许短的if语句保持在同一行</span><br><span class="hljs-attr">AllowShortIfStatementsOnASingleLine:</span> <span class="hljs-literal">true</span><br><br><span class="hljs-comment"># 允许短的循环保持在同一行</span><br><span class="hljs-attr">AllowShortLoopsOnASingleLine:</span> <span class="hljs-literal">true</span><br><br><span class="hljs-comment"># 总是在返回类型后换行: None, All, TopLevel(顶级函数，不包括在类中的函数), </span><br><span class="hljs-comment"># AllDefinitions(所有的定义，不包括声明), TopLevelDefinitions(所有的顶级函数的定义)</span><br><span class="hljs-attr">AlwaysBreakAfterReturnType:</span> <span class="hljs-string">None</span><br><br><span class="hljs-comment"># 总是在多行string字面量前换行</span><br><span class="hljs-attr">AlwaysBreakBeforeMultilineStrings:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-comment"># 总是在template声明后换行</span><br><span class="hljs-attr">AlwaysBreakTemplateDeclarations:</span> <span class="hljs-literal">true</span><br><br><span class="hljs-comment"># false表示函数实参要么都在同一行，要么都各自一行</span><br><span class="hljs-attr">BinPackArguments:</span> <span class="hljs-literal">true</span><br><br><span class="hljs-comment"># false表示所有形参要么都在同一行，要么都各自一行</span><br><span class="hljs-attr">BinPackParameters:</span> <span class="hljs-literal">true</span><br><br><span class="hljs-comment"># 大括号换行，只有当BreakBeforeBraces设置为Custom时才有效</span><br><span class="hljs-attr">BraceWrapping:</span><br>  <span class="hljs-comment"># class定义后面</span><br>  <span class="hljs-attr">AfterClass:</span> <span class="hljs-literal">false</span><br>  <span class="hljs-comment"># 控制语句后面</span><br>  <span class="hljs-attr">AfterControlStatement:</span> <span class="hljs-literal">false</span><br>  <span class="hljs-comment"># enum定义后面</span><br>  <span class="hljs-attr">AfterEnum:</span> <span class="hljs-literal">false</span><br>  <span class="hljs-comment"># 函数定义后面</span><br>  <span class="hljs-attr">AfterFunction:</span> <span class="hljs-literal">false</span><br>  <span class="hljs-comment"># 命名空间定义后面</span><br>  <span class="hljs-attr">AfterNamespace:</span> <span class="hljs-literal">false</span><br>  <span class="hljs-comment"># struct定义后面</span><br>  <span class="hljs-attr">AfterStruct:</span> <span class="hljs-literal">false</span><br>  <span class="hljs-comment"># union定义后面</span><br>  <span class="hljs-attr">AfterUnion:</span> <span class="hljs-literal">false</span><br>  <span class="hljs-comment"># extern之后</span><br>  <span class="hljs-attr">AfterExternBlock:</span> <span class="hljs-literal">false</span><br>  <span class="hljs-comment"># catch之前</span><br>  <span class="hljs-attr">BeforeCatch:</span> <span class="hljs-literal">false</span><br>  <span class="hljs-comment"># else之前</span><br>  <span class="hljs-attr">BeforeElse:</span> <span class="hljs-literal">false</span><br>  <span class="hljs-comment"># 缩进大括号</span><br>  <span class="hljs-attr">IndentBraces:</span> <span class="hljs-literal">false</span><br>  <span class="hljs-comment"># 分离空函数</span><br>  <span class="hljs-attr">SplitEmptyFunction:</span> <span class="hljs-literal">false</span><br>  <span class="hljs-comment"># 分离空语句</span><br>  <span class="hljs-attr">SplitEmptyRecord:</span> <span class="hljs-literal">false</span><br>  <span class="hljs-comment"># 分离空命名空间</span><br>  <span class="hljs-attr">SplitEmptyNamespace:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-comment"># 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行)</span><br><span class="hljs-attr">BreakBeforeBinaryOperators:</span> <span class="hljs-string">NonAssignment</span><br><br><span class="hljs-comment"># 在大括号前换行: Attach(始终将大括号附加到周围的上下文), Linux(除函数、命名空间和类定义，与Attach类似), </span><br><span class="hljs-comment">#   Mozilla(除枚举、函数、记录定义，与Attach类似), Stroustrup(除函数定义、catch、else，与Attach类似), </span><br><span class="hljs-comment">#   Allman(总是在大括号前换行), GNU(总是在大括号前换行，并对于控制语句的大括号增加额外的缩进), WebKit(在函数前换行), Custom</span><br><span class="hljs-comment">#   注：这里认为语句块也属于函数</span><br><span class="hljs-attr">BreakBeforeBraces:</span> <span class="hljs-string">Custom</span><br><br><span class="hljs-comment"># 在三元运算符前换行</span><br><span class="hljs-attr">BreakBeforeTernaryOperators:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-comment"># 在构造函数的初始化列表的冒号后换行</span><br><span class="hljs-attr">BreakConstructorInitializers:</span> <span class="hljs-string">AfterColon</span><br><br><span class="hljs-comment">#BreakInheritanceList: AfterColon</span><br><br><span class="hljs-attr">BreakStringLiterals:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-comment"># 每行字符的限制，0表示没有限制</span><br><span class="hljs-attr">ColumnLimit:</span> <span class="hljs-number">0</span><br><br><span class="hljs-attr">CompactNamespaces:</span> <span class="hljs-literal">true</span><br><br><span class="hljs-comment"># 构造函数的初始化列表要么都在同一行，要么都各自一行</span><br><span class="hljs-attr">ConstructorInitializerAllOnOneLineOrOnePerLine:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-comment"># 构造函数的初始化列表的缩进宽度</span><br><span class="hljs-attr">ConstructorInitializerIndentWidth:</span> <span class="hljs-number">4</span><br><br><span class="hljs-comment"># 延续的行的缩进宽度</span><br><span class="hljs-attr">ContinuationIndentWidth:</span> <span class="hljs-number">4</span><br><br><span class="hljs-comment"># 去除C++11的列表初始化的大括号&#123;后和&#125;前的空格</span><br><span class="hljs-attr">Cpp11BracedListStyle:</span> <span class="hljs-literal">true</span><br><br><span class="hljs-comment"># 继承最常用的指针和引用的对齐方式</span><br><span class="hljs-attr">DerivePointerAlignment:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-comment"># 固定命名空间注释</span><br><span class="hljs-attr">FixNamespaceComments:</span> <span class="hljs-literal">true</span><br><br><span class="hljs-comment"># 缩进case标签</span><br><span class="hljs-attr">IndentCaseLabels:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-attr">IndentPPDirectives:</span> <span class="hljs-string">None</span><br><br><span class="hljs-comment"># 缩进宽度</span><br><span class="hljs-attr">IndentWidth:</span> <span class="hljs-number">4</span><br><br><span class="hljs-comment"># 函数返回类型换行时，缩进函数声明或函数定义的函数名</span><br><span class="hljs-attr">IndentWrappedFunctionNames:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-comment"># 保留在块开始处的空行</span><br><span class="hljs-attr">KeepEmptyLinesAtTheStartOfBlocks:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-comment"># 连续空行的最大数量</span><br><span class="hljs-attr">MaxEmptyLinesToKeep:</span> <span class="hljs-number">1</span><br><br><span class="hljs-comment"># 命名空间的缩进: None, Inner(缩进嵌套的命名空间中的内容), All</span><br><span class="hljs-attr">NamespaceIndentation:</span> <span class="hljs-string">None</span><br><br><span class="hljs-comment"># 指针和引用的对齐: Left, Right, Middle</span><br><span class="hljs-attr">PointerAlignment:</span> <span class="hljs-string">Right</span><br><br><span class="hljs-comment"># 允许重新排版注释</span><br><span class="hljs-attr">ReflowComments:</span> <span class="hljs-literal">true</span><br><br><span class="hljs-comment"># 允许排序#include</span><br><span class="hljs-attr">SortIncludes:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-comment"># 允许排序 using 声明</span><br><span class="hljs-attr">SortUsingDeclarations:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-comment"># 在C风格类型转换后添加空格</span><br><span class="hljs-attr">SpaceAfterCStyleCast:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-comment"># 在Template 关键字后面添加空格</span><br><span class="hljs-attr">SpaceAfterTemplateKeyword:</span> <span class="hljs-literal">true</span><br><br><span class="hljs-comment"># 在赋值运算符之前添加空格</span><br><span class="hljs-attr">SpaceBeforeAssignmentOperators:</span> <span class="hljs-literal">true</span><br><br><span class="hljs-comment"># SpaceBeforeCpp11BracedList: true</span><br><br><span class="hljs-comment"># SpaceBeforeCtorInitializerColon: true</span><br><br><span class="hljs-comment"># SpaceBeforeInheritanceColon: true</span><br><br><span class="hljs-comment"># 开圆括号之前添加一个空格: Never, ControlStatements, Always</span><br><span class="hljs-attr">SpaceBeforeParens:</span> <span class="hljs-string">ControlStatements</span><br><br><span class="hljs-comment"># SpaceBeforeRangeBasedForLoopColon: true</span><br><br><span class="hljs-comment"># 在空的圆括号中添加空格</span><br><span class="hljs-attr">SpaceInEmptyParentheses:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-comment"># 在尾随的评论前添加的空格数(只适用于//)</span><br><span class="hljs-attr">SpacesBeforeTrailingComments:</span> <span class="hljs-number">1</span><br><br><span class="hljs-comment"># 在尖括号的&lt;后和&gt;前添加空格</span><br><span class="hljs-attr">SpacesInAngles:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-comment"># 在C风格类型转换的括号中添加空格</span><br><span class="hljs-attr">SpacesInCStyleCastParentheses:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-comment"># 在容器(ObjC和JavaScript的数组和字典等)字面量中添加空格</span><br><span class="hljs-attr">SpacesInContainerLiterals:</span> <span class="hljs-literal">true</span><br><br><span class="hljs-comment"># 在圆括号的(后和)前添加空格</span><br><span class="hljs-attr">SpacesInParentheses:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-comment"># 在方括号的[后和]前添加空格，lamda表达式和未指明大小的数组的声明不受影响</span><br><span class="hljs-attr">SpacesInSquareBrackets:</span> <span class="hljs-literal">false</span><br><br><span class="hljs-comment"># 标准: Cpp03, Cpp11, Auto</span><br><span class="hljs-attr">Standard:</span> <span class="hljs-string">Auto</span><br><br><span class="hljs-comment"># tab宽度</span><br><span class="hljs-attr">TabWidth:</span> <span class="hljs-number">4</span><br><br><span class="hljs-comment"># 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always</span><br><span class="hljs-attr">UseTab:</span> <span class="hljs-string">Never</span><br></code></pre></td></tr></table></figure>



<h2 id="4-Windows上配置"><a href="#4-Windows上配置" class="headerlink" title="4. Windows上配置"></a>4. Windows上配置</h2><h3 id="4-1-工具链安装"><a href="#4-1-工具链安装" class="headerlink" title="4.1 工具链安装"></a>4.1 工具链安装</h3><p>不知道大家有没有注意过自己用的工具链版本</p>
<p>较为知名的几个项目:</p>
<ul>
<li>MinGW-w64项目多年不更新，gcc版本停留在8.1,与linux下ubuntu20.04 LTS 9.0 ,Arch 11.2差的很远；</li>
<li>tdm-gcc在停更了好多年之后，更新了10.0版本</li>
</ul>
<p>推荐以下两种方式</p>
<ul>
<li><p><a target="_blank" rel="noopener" href="https://winlibs.com/">Winlib</a> 主要提供GCC 和 LLVM 在windows下的 使用 基本上上游更新，作者就会编译发布</p>
<img src="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/202203301905350.png" srcset="/img/loading1.gif" lazyload alt="image-20220330190524242" style="zoom:67%;" />

<p>因为是LLVM官方在windows上似乎只提供了MSVC版本的，所以可能存在问题，我目前使用的版本lldb就存在python依赖问题</p>
</li>
<li><p><a target="_blank" rel="noopener" href="https://www.msys2.org/">MYSY2</a> 模拟Linux环境，使用Pacman 作为包管理器，作为一个曾经在物理机上安装Arch Linux 的人，Pacman 的强大让我念念不忘，可惜的是Linux下没有好用的QQ,微信。Pacman 中有最新的软件包和几乎永远不需要担心依赖和编译问题，在配置环境中带来巨大痛苦的OpenGL,OpenCV,Eigen，甚至是hadoop的安装只需要一条命令，已经有人为你做好了一切，包管理器让更新变得十分容易。</p>
<img src="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/202205081312305.png" srcset="/img/loading1.gif" lazyload alt="image-20220508131232171" style="zoom:67%;" />

<p>将<code>msys2 shell</code>集成在 Windows Terminal中，命令行<code>C:\Users\FengisZZZ\ServerTools\msys\msys2_shell.cmd -msys -defterm -no-start</code>;</p>
<p>集成在VScode中,</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-attr">&quot;msys2&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>          <span class="hljs-attr">&quot;path&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;C:\\Users\\FengisZZZ\\ServerTools\\msys\\usr\\bin\\bash.exe&quot;</span><span class="hljs-punctuation">,</span><br>          <span class="hljs-attr">&quot;args&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>              <span class="hljs-string">&quot;--login&quot;</span><span class="hljs-punctuation">,</span><br>              <span class="hljs-string">&quot;-i&quot;</span><br>          <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>          <span class="hljs-attr">&quot;env&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>              <span class="hljs-attr">&quot;MSYSTEM&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;MINGW64&quot;</span><span class="hljs-punctuation">,</span><br>              <span class="hljs-attr">&quot;CHERE_INVOKING&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;1&quot;</span><span class="hljs-punctuation">,</span><br>              <span class="hljs-attr">&quot;MSYS2_PATH_TYPE&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;inherit&quot;</span><br>          <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>          <span class="hljs-attr">&quot;color&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;terminal.ansiYellow&quot;</span><span class="hljs-punctuation">,</span><br>          <span class="hljs-attr">&quot;icon&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;terminal-bash&quot;</span><br>      <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br></code></pre></td></tr></table></figure></li>
</ul>
<p>使用msys2安装工具链的时候，<code>因为clang 和 mingw-w64是两套完全不同的工具链，分别在mingw64，clang64目录下，而且第三方包并不共享，因此推荐安装mingw-w64版的clang,llvm</code></p>
<p>例如使用tdmgcc64（一个mingw-w64的windows发行版） 编译的opencv在使用clang64文件夹下的clang++是无法通过编译的</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># mingw-w64工具链</span><br>pacman -S --needed base-devel mingw-w64-x86_64-toolchain<br><span class="hljs-comment"># 包含clang,clang++等工具</span><br>mingw-w64-x86_64-clang<br><span class="hljs-comment"># clangd clang-tidy等工具</span><br>mingw-w64-x86_64-clang-tools-extra<br><span class="hljs-comment"># llvm相关</span><br>mingw-w64-x86_64-llvm<br></code></pre></td></tr></table></figure>

<p>安装后发现clang,clang++,clangd都在<code>./mingw64/bin</code>目录下,<code>./clang64</code>下都是空目录</p>
<p>记得添加环境变量</p>
<img src="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/202205081323254.png" srcset="/img/loading1.gif" lazyload alt="image-20220508131557192" style="zoom:67%;" />

<h3 id="4-2-json配置"><a href="#4-2-json配置" class="headerlink" title="4.2 json配置"></a>4.2 json配置</h3><p>因为上述安装的包都是为了mingw-w64工具链而服务，所以我们可以使用clang++编译，gdb调试；正常安装clang,mingw-w64则不能如此。</p>
<p>同时还有意外惊喜:smile:，就是可以将cpp文件命名为中文，只用g++,gdb不能正常打断点调试，而用clang++是可以的。</p>
<p>以下是<code>使用c/c++ 插件</code>的配置，分别表示使用g++编译，和clang++编译。</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-punctuation">&#123;</span><br>    <span class="hljs-attr">&quot;tasks&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>        <span class="hljs-punctuation">&#123;</span><br>            <span class="hljs-attr">&quot;type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;shell&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;label&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;g++ build&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;command&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;C:\\Users\\FengisZZZ\\ServerTools\\msys\\mingw64\\bin\\g++.exe&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;args&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>                <span class="hljs-string">&quot;-fdiagnostics-color=always&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;-g&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;$&#123;file&#125;&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;-Wall&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;-o&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;\\bin\\$&#123;fileBasenameNoExtension&#125;.exe&quot;</span><br>            <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;options&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>                <span class="hljs-attr">&quot;cwd&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;&quot;</span><br>            <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;problemMatcher&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>                <span class="hljs-string">&quot;$gcc&quot;</span><br>            <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;group&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>                <span class="hljs-attr">&quot;kind&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;build&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-attr">&quot;isDefault&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><br>            <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;presentation&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>                <span class="hljs-attr">&quot;echo&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span><br>                <span class="hljs-attr">&quot;panel&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;shared&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-attr">&quot;reveal&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;always&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-attr">&quot;focus&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><br>            <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-punctuation">&#123;</span><br>            <span class="hljs-attr">&quot;type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;shell&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;label&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;clang++ build&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;command&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;C:\\Users\\FengisZZZ\\ServerTools\\msys\\mingw64\\bin\\clang++.exe&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;args&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>                <span class="hljs-string">&quot;-g&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;$&#123;file&#125;&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;-Wall&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;-o&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;\\bin\\leetcode.exe&quot;</span><br>            <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;options&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>                <span class="hljs-attr">&quot;cwd&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;&quot;</span><br>            <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;problemMatcher&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>                <span class="hljs-string">&quot;$gcc&quot;</span><br>            <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;group&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>                <span class="hljs-attr">&quot;kind&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;build&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-attr">&quot;isDefault&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><br>            <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;presentation&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>                <span class="hljs-attr">&quot;echo&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span><br>                <span class="hljs-attr">&quot;panel&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;shared&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-attr">&quot;reveal&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;always&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-attr">&quot;focus&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><br>            <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-punctuation">&#125;</span><br>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-attr">&quot;version&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;2.0.0&quot;</span><br><span class="hljs-punctuation">&#125;</span><br></code></pre></td></tr></table></figure>

<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-punctuation">&#123;</span><br>    <span class="hljs-attr">&quot;version&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;0.2.0&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-attr">&quot;configurations&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>        <span class="hljs-punctuation">&#123;</span><br>            <span class="hljs-attr">&quot;name&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;gcc debug&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;cppdbg&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;request&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;launch&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;program&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;\\bin\\$&#123;fileBasenameNoExtension&#125;.exe&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;args&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;stopAtEntry&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;cwd&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;environment&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;externalConsole&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;internalConsoleOptions&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;neverOpen&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;MIMode&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;gdb&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;miDebuggerPath&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;C:\\Users\\FengisZZZ\\ServerTools\\msys\\mingw64\\bin\\gdb.exe&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;setupCommands&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>                <span class="hljs-punctuation">&#123;</span><br>                    <span class="hljs-attr">&quot;description&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;为 gdb 启用整齐打印&quot;</span><span class="hljs-punctuation">,</span><br>                    <span class="hljs-attr">&quot;text&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;-enable-pretty-printing&quot;</span><span class="hljs-punctuation">,</span><br>                    <span class="hljs-attr">&quot;ignoreFailures&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><br>                <span class="hljs-punctuation">&#125;</span><br>            <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;preLaunchTask&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;g++ build&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-punctuation">&#123;</span><br>            <span class="hljs-attr">&quot;name&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;clang debug&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;cppdbg&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;request&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;launch&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;program&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;\\bin\\leetcode.exe&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;args&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;stopAtEntry&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;cwd&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;environment&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;externalConsole&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;internalConsoleOptions&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;neverOpen&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;MIMode&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;gdb&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;miDebuggerPath&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;C:\\Users\\FengisZZZ\\ServerTools\\msys\\mingw64\\bin\\gdb.exe&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;setupCommands&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>                <span class="hljs-punctuation">&#123;</span><br>                    <span class="hljs-attr">&quot;description&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;为 gdb 启用整齐打印&quot;</span><span class="hljs-punctuation">,</span><br>                    <span class="hljs-attr">&quot;text&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;-enable-pretty-printing&quot;</span><span class="hljs-punctuation">,</span><br>                    <span class="hljs-attr">&quot;ignoreFailures&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><br>                <span class="hljs-punctuation">&#125;</span><br>            <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;preLaunchTask&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;clang++ build&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-punctuation">&#125;</span><br>    <span class="hljs-punctuation">]</span><br><span class="hljs-punctuation">&#125;</span><br></code></pre></td></tr></table></figure>



<p><code>未完 待续</code></p>
<h2 id="附"><a href="#附" class="headerlink" title="附"></a>附</h2><p><code>参考链接:</code></p>
<ul>
<li>Bilibili</li>
</ul>
<p><a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1sW411v7VZ?p=1"> VS Code + Clangd + CMake 搭建 C&#x2F;C++开发环境</a></p>
<ul>
<li>CSDN:</li>
</ul>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/tyKuGengty/article/details/120119820">VSCode 配置 C&#x2F;C++：VSCode + Clang + Clangd + LLDB + CMake + Git</a></p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/weixin_43862847/article/details/119274382">vscode + clangd 开发 c&#x2F;c++</a></p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE/" class="category-chain-item">环境配置</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE/" class="print-no-link">#环境配置</a>
      
        <a href="/tags/C/" class="print-no-link">#C++</a>
      
        <a href="/tags/Visual-Studio-Code/" class="print-no-link">#Visual Studio Code</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>在vscode上使用clangd</div>
      <div>http://example.com/2022/03/28/在vscode上使用clangd/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Feng Zikai</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年3月28日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/04/01/ubuntu-%E9%85%8D%E7%BD%AEopenstack/" title="ubuntu 配置openstack">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">ubuntu 配置openstack</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/03/19/%E4%BA%91%E8%AE%A1%E7%AE%97%E4%BD%9C%E4%B8%9A2/" title="云计算作业2">
                        <span class="hidden-mobile">云计算作业2</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> <div style="font-size: 0.85rem"> <span id="timeDate">载入天数...</span> <span id="times">载入时分秒...</span> <script src="/js/duration.js"></script> </div> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.4/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.20.1/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>




  
<script src="//cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script>
<script src="//cdn.jsdelivr.net/gh/metowolf/Metingjs@1.2/dist/Meting.min.js"></script>
<script src="//cdn.bootcss.com/animejs/2.2.0/anime.min.js"></script>



<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
